<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ArkfulDodger</title>
    <description>The latest articles on DEV Community by ArkfulDodger (@arkfuldodger).</description>
    <link>https://dev.to/arkfuldodger</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F819436%2F9c366838-f371-4e57-99e9-8d4db2c6ffe8.png</url>
      <title>DEV Community: ArkfulDodger</title>
      <link>https://dev.to/arkfuldodger</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arkfuldodger"/>
    <language>en</language>
    <item>
      <title>macOS Keyboard Shortcuts for Arranging your Windows</title>
      <dc:creator>ArkfulDodger</dc:creator>
      <pubDate>Wed, 18 May 2022 20:44:38 +0000</pubDate>
      <link>https://dev.to/arkfuldodger/macos-keyboard-shortcuts-for-arranging-your-windows-2h44</link>
      <guid>https://dev.to/arkfuldodger/macos-keyboard-shortcuts-for-arranging-your-windows-2h44</guid>
      <description>&lt;p&gt;If you're a developer, or anyone who spends most of their day typing away at the computer, chances are good that you have your own personal set of keyboard shortcuts that are your go-to's. I'm here to share with you one of my personal favorites in terms of global quality of life improvements, and how you can get it set up on your macOS computer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Arranging Windows with Keyboard Shortcuts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Goal:&lt;/strong&gt; change the positioning/sizing of a window or windows without ever touching the mouse&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Our Limitations:&lt;/strong&gt; repositioning and resizing windows (regardless of application) is possible on Mac, but only the specified options below. For any more nuanced repositioning of your workspace using the keyboard, you may need to look into downloading software specifically for the task.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How We'll Do It:&lt;/strong&gt; The way we make this work is by using the ability to create custom keyboard shortcuts on macOS, and by using the pre-existing commands that mac has for positioning windows, which you can see by hovering over the green button (often called the "maximize" button) at the top left of any open window, as seen below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bBu8QsfX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6y9fke4o6bn6a7l4wjs8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bBu8QsfX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6y9fke4o6bn6a7l4wjs8.png" alt="cursor hovering over the green maximize button on a window, displaying the following options in a list: Enter Full Screen, Zoom, Tile Window to Left of Screen, Move Window to Left Side of Screen, Tile Window to Right of Screen, Move Window to Right Side of Screen, and Move to DELL U2518D" width="814" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that the commands shown here change contextually, and may appear differently for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the Shortcuts
&lt;/h2&gt;

&lt;p&gt;To create our keyboard shortcuts, start by going to your mac's keyboard settings. You can do this quickly (using shortcuts!) by pressing CMD + SPACE to open the search bar, typing "keyboard", and pressing RETURN when the keyboard settings option shows up.&lt;/p&gt;

&lt;p&gt;From here, click the "Shortcuts" tab option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FE7sA5gR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9fz4t4gh1v8aj5xo0gz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FE7sA5gR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c9fz4t4gh1v8aj5xo0gz.png" alt='The Keyboard Settings tabs with the central "Shortcuts" tab indicated' width="662" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here, select "App Shortcuts" from the list on the left. This will display your App-level keyboard shortcuts on your machine, there may be one or two already here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XeY6mp89--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ei64kbsdwt73542s3rm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XeY6mp89--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5ei64kbsdwt73542s3rm.png" alt='The Keyboard Shortcuts page, with "App Shortcuts" selected from the list on the left, and a number of shortcuts listed on the right under the sections "All Applications" and "Google Chrome"' width="658" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, press the + button to create a new shortcut, and fill in the entries as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application:&lt;/strong&gt; select "All Applications". This will mean that the shortcut(s) we are creating will be accessible regardless of the application we are using.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Menu Title:&lt;/strong&gt; enter the name of the command you wish to map to the keyboard shortcut &lt;em&gt;exactly as it appears in the menu&lt;/em&gt;. This must be a character-for-character match in order to work. Note that if you use multiple screens like me, each screen will have a specific name you must use in order to move windows to that screen, so when in doubt, check how it is listed!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keyboard Shortcut:&lt;/strong&gt; Enter the shortcut you wish to use. It is a good idea to use shortcuts that are unlikely to be in use by any other application (you can see the shortcuts I use in the screenshots above).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that is all there is to it! You should now be able to use your custom keyboard shortcuts to move, tile, fullscreen, and/or zoom your windows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Notes and Troubleshooting
&lt;/h2&gt;

&lt;p&gt;It may sometimes be impossible to find a series of keyboard combinations that are unused by all of the applications you frequent, and you will probably find that application-level keyboard shortcuts override anything you set here (usually a good thing!).&lt;/p&gt;

&lt;p&gt;In these cases, your options might be to list multiple keyboard shortcuts for the same command, and ensure that the backup shortcut works in the application you are trying to use.&lt;/p&gt;

&lt;p&gt;My preferred solution however is often to see if the application in question will give me control over its keyboard shortcuts, and alter the conflicting shortcut(s) to be different (assuming I don't need the native shortcut of course!).&lt;/p&gt;

&lt;p&gt;I personally did this in VS Code for the shortcuts in the images above for moving windows from one side of the screen to the other. It's all about finding which solution is best for your personal workflow.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Ruby VS Code Snippets</title>
      <dc:creator>ArkfulDodger</dc:creator>
      <pubDate>Fri, 08 Apr 2022 19:38:31 +0000</pubDate>
      <link>https://dev.to/arkfuldodger/ruby-vs-code-snippets-37id</link>
      <guid>https://dev.to/arkfuldodger/ruby-vs-code-snippets-37id</guid>
      <description>&lt;p&gt;I have a minor addiction to writing snippets. Below are a few of the ones I have created for use in programming with Ruby. Feel free to add these to your own snippet files in VS Code!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPDATE: 4/11/21:&lt;/strong&gt; Init Var, Init Attr, and Class Setup snippets updated. Will now work with keyword arguments and arguments with default values&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ref for adding custom snippets to VS Code:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/29995863/how-to-add-custom-code-snippets-in-vscode#answers" rel="noopener noreferrer"&gt;Stack Overflow: How to Add Custom Code Snippets in VSCode&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets" rel="noopener noreferrer"&gt;VS Code Snippets Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;My blog post on VS Code Snippet Transformations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/arkfuldodger/transforming-vs-code-snippets-4jcc"&gt;VS Code Snippet Transformations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The program I use to record my gifs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cockos.com/licecap/" rel="noopener noreferrer"&gt;LICEcap&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Snippet List
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Initialize with Variable Assignments&lt;/li&gt;
&lt;li&gt;Initialize with Attr_Accessor&lt;/li&gt;
&lt;li&gt;Class Setup&lt;/li&gt;
&lt;li&gt;All Variable&lt;/li&gt;
&lt;li&gt;ActiveRecord Model Class&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Initialize with Variable Assignments &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"Initialize With Var Assign"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"init var"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"def initialize($1$2)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;${1/^(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?|,&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?/${6:+&lt;/span&gt;&lt;span class="se"&gt;\n\t&lt;/span&gt;&lt;span class="s2"&gt;}@$1$6 = $1$6/g}$0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"end"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; creates initialize method for a class, taking arguments which are assigned to class-scoped variables&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvutpq82c5omf2mmwutv2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvutpq82c5omf2mmwutv2.gif" alt="Animated Gif showing demo of Init Var Snippet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How-To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prefix:&lt;/strong&gt; "init var"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tabstop 1:&lt;/strong&gt; enter any parameters which should be set as class variables, separated by a comma

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;format will update after tabbing out of this tabstop&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 2:&lt;/strong&gt; enter any parameters which should not be set as class variables, separated by a comma&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 0:&lt;/strong&gt; cursor placed within end of initialize method&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Initialize with Attr_Accessor &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"Initialize With Attr"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"init attr"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"attr_accessor ${1/^(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?|,&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?/${6:+, }:$1$6/g}$3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"def initialize($1$2)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;${1/^(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?|,&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?/${6:+&lt;/span&gt;&lt;span class="se"&gt;\n\t&lt;/span&gt;&lt;span class="s2"&gt;}@$1$6 = $1$6/g}$0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"end"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; creates initialize method for a class, as with the prior snippet, but additionally creates attr_accessors for each class variable set&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmfddp5hynxlu0o9xk675.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmfddp5hynxlu0o9xk675.gif" alt="Animated Gif showing demo of Init Attr Snippet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How-To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prefix:&lt;/strong&gt; "init attr"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tabstop 1:&lt;/strong&gt; enter any initialize method parameters which should be set as class variables and attr_accessors, separated by a comma

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;format will update after tabbing out of this tabstop&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 2:&lt;/strong&gt; enter any initialize method parameters which should not be set as class variables, separated by a comma&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 3:&lt;/strong&gt; enter any additional attr_accessors, or enter other needed code such as attr_readers on a new line&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 0:&lt;/strong&gt; cursor placed within end of initialize method&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Class Setup &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"Class Setup"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"class setup"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"class ${1:${TM_FILENAME_BASE/[^a-zA-Z]*([a-zA-Z]+.*_.*)|[^a-zA-Z]*([a-zA-Z].*)/${1:/pascalcase}${2:/capitalize}/}}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;attr_accessor ${2/^(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?|,&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?/${6:+, }:$1$6/g}$4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;def initialize($2$3)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t\t&lt;/span&gt;&lt;span class="s2"&gt;${2/^(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?|,&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*(&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;w+)((:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*=&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;s*)((&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;[^&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;]*&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;|'[^']*'|&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[[^&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]]*&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;]|{[^}]*})?[^,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s2"&gt;[{]*)*)?/${6:+&lt;/span&gt;&lt;span class="se"&gt;\n\t\t&lt;/span&gt;&lt;span class="s2"&gt;}@$1$6 = $1$6/g}$5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;end"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;$0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"end"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; creates initialize method and attr_accessors, as with the prior snippet, but also creates the containing class definition which derives its name from the filename&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlk1qdgtstvo6dpsk0p3.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjlk1qdgtstvo6dpsk0p3.gif" alt="Animated Gif showing demo of Class Setup Snippet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How-To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prefix:&lt;/strong&gt; "class setup"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tabstop 1:&lt;/strong&gt; enter class name

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;by default, will be set to file name in PascalCase (UpperCamelCase) omitting leading numbers&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 2:&lt;/strong&gt; enter any initialize method parameters which should be set as class variables and attr_accessors, separated by a comma

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;format will update after tabbing out of this tabstop&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 3:&lt;/strong&gt; enter any initialize method parameters which should not be set as class variables, separated by a comma&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 4:&lt;/strong&gt; enter any additional attr_accessors, or enter other needed code such as attr_readers on a new line&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 5:&lt;/strong&gt; enter any additional code within initialize method&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 0:&lt;/strong&gt; cursor placed within end of class definition&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  All Variable &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"All Class Variable"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;@@all = []"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"${TM_SELECTED_TEXT/(end)$/&lt;/span&gt;&lt;span class="se"&gt;\n\t\t&lt;/span&gt;&lt;span class="s2"&gt;@@all &amp;lt;&amp;lt; self&lt;/span&gt;&lt;span class="se"&gt;\n\t&lt;/span&gt;&lt;span class="s2"&gt;end/}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;def self.all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t\t&lt;/span&gt;&lt;span class="s2"&gt;@all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;end"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; for an existing class, creates class-level &lt;strong&gt;@@all&lt;/strong&gt; variable to contain array of class instances, adds instance to array within initialize method, and creates class-level get method&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncvscsbvt4gtj61hfa76.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncvscsbvt4gtj61hfa76.gif" alt="Animated Gif showing demo of All Variable Snippet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How-To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Select:&lt;/strong&gt; initialize method, starting with the beginning of the first row through the final word "end" closing the method definition

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;NOTE&lt;/em&gt;: the "end" must be the final characters in your selection for the snippet to work properly. If they are not, the shovel method within initialize will not generate&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Type Prefix:&lt;/strong&gt; "all"&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 0:&lt;/strong&gt; cursor placed at end of getter method&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  ActiveRecord Model Class &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"ActiveRecord Class"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ar class"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"class ${1:${TM_FILENAME_BASE/[^a-zA-Z]*([a-zA-Z]+.*_.*)|[^a-zA-Z]*([a-zA-Z].*)/${1:/pascalcase}${2:/capitalize}/}} &amp;lt; ActiveRecord::Base"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="s2"&gt;$0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"end"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Purpose:&lt;/strong&gt; creates basic class definition with inheritance for use with the ActiveRecord ORM gem&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Demo:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1jcnfv559psxlmsma32.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu1jcnfv559psxlmsma32.gif" alt="Animated Gif showing demo of ActiveRecord Class Snippet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How-To:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prompt:&lt;/strong&gt; "ar class" &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tabstop 1:&lt;/strong&gt; enter class name

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;by default, will be set to file name in PascalCase (UpperCamelCase) omitting leading numbers&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Tabstop 0:&lt;/strong&gt; cursor placed within class definition&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>vscode</category>
      <category>ruby</category>
      <category>productivity</category>
      <category>snippets</category>
    </item>
    <item>
      <title>Transforming VS Code Snippets</title>
      <dc:creator>ArkfulDodger</dc:creator>
      <pubDate>Wed, 06 Apr 2022 14:30:38 +0000</pubDate>
      <link>https://dev.to/arkfuldodger/transforming-vs-code-snippets-4jcc</link>
      <guid>https://dev.to/arkfuldodger/transforming-vs-code-snippets-4jcc</guid>
      <description>&lt;h2&gt;
  
  
  VS Code Snippets
&lt;/h2&gt;

&lt;p&gt;If you're here, you probably know what snippets are, and have maybe even dabbled in making your own. As such, you're familiar with some or all of the basic features/benefits of snippets outlined below:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Snippet Features/Benefits&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;quickly output pre-written code (save repetitive typing)&lt;/li&gt;
&lt;li&gt;use &lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets#_tabstops"&gt;tabstops&lt;/a&gt; to navigate your cursor to predetermined locations in your snippet using the tab key&lt;/li&gt;
&lt;li&gt;use multiple occurrences of the same tab stop to enter recurring values only once&lt;/li&gt;
&lt;li&gt;use &lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets#_placeholders"&gt;placeholder values&lt;/a&gt; to provide default values to tabstops&lt;/li&gt;
&lt;li&gt;give &lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets#_choice"&gt;placeholder choice options&lt;/a&gt; (as from a dropdown) to be selected when the snippet is inserted&lt;/li&gt;
&lt;li&gt;insert &lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables"&gt;certain variable values&lt;/a&gt; into your snippets&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you're new to making your own snippets, I highly recommend working on each of these in turn, as they build on each other well and are simple enough to pick up. With only these 6, you can create a great many incredibly useful snippets.&lt;/p&gt;

&lt;p&gt;Here, I am going to cover one of the tricker, but more powerful customizations you can add to your snippets to further streamline your own coding process:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Variable and Placeholder Transformations&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Transformations
&lt;/h2&gt;

&lt;p&gt;Transformations in our snippets take either a variable or placeholder and modify it in some way.&lt;/p&gt;

&lt;p&gt;Why would we do this? Let's look at one practical use-case example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use-Case Example: React Use State Declaration
&lt;/h2&gt;

&lt;p&gt;Let's say you're programming in React and want to declare a new state. Not familiar with React? Don't worry about it. For this example, just know that declaring state involves creating a variable as well as a method used to set the value of that variable. This is declared as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;fooBar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFooBar&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have our variable "fooBar" and our method "setFooBar". By convention, the method is named as "set____" using the name of the variable. Both are in camelCase.&lt;/p&gt;

&lt;p&gt;If we were making a snippet for this, we might write our snippet body as something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"const [$1, set$2] = useState();"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This snippet is functional, but note that we are typing the same variable name twice. We could replace the "$2" tabstop with "$1", but we will quickly run into the issue that the second occurrence comes out as &lt;code&gt;setfooBar&lt;/code&gt; and no longer adheres to our camelCase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we want is a way to type the variable once, and capitalize the first letter of the second occurrence.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To achieve this we use a placeholder transform to insert tabstop $1 and change it to our specifications. The new snippet code is as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"const [$1, set${1/(.*)/${1:/capitalize}/}] = useState()"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay, it looks like there's a lot going on in there, so let's break it down into pieces and put it back together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transformation Structure/Syntax
&lt;/h2&gt;

&lt;p&gt;To start, let's think of a transform in terms of a series of questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What are we transforming?&lt;/li&gt;
&lt;li&gt;What part(s) of that thing are we transforming?&lt;/li&gt;
&lt;li&gt;How are we changing each part?&lt;/li&gt;
&lt;li&gt;Are there any additional details or modifications?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's get our bearings in the code by looking at the syntax of a transformation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;${«variable|tabstop»/«regexp»/«text|format»/«options»}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The transform is contained inside "{}" curly brackets preceded by a "$" dollar sign and is divided into four sections by "/" forward slashes. Each section directly relates back to our questions thusly:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What are we transforming?

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;variable or tabstop:&lt;/strong&gt; the variable or tabstop input being transformed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;What part(s) of that thing are we transforming?

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;regex:&lt;/strong&gt; a regular expression that searches for matches in the variable/tabstop&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;How are we changing each part?

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;text or format:&lt;/strong&gt; the text to insert in place of the match(es) found by the regex, or the format indicating how to return or act upon the match(es) found by the regex&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Are there any additional details or modifications?

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;options:&lt;/strong&gt; additional options for the regex, often blank (we won't use or go into this in this example)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Structure of our Example Transformation
&lt;/h2&gt;

&lt;p&gt;Now let's see how these sections present themselves in the transformation we used above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;${1/(.*)/${1:/capitalize}/}    // the full transformation
${ /    /                /}    // container and dividers
  1                            // tabstop reference
    (.*)                       // regex
         ${1:/capitalize}      // format
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's touch on each of the three sections in play (section 4, options, is not used here):&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Tabstop&lt;/strong&gt; - &lt;em&gt;What is being transformed?&lt;/em&gt;&lt;/u&gt;&lt;br&gt;
The tabstop reference is relatively self explanatory. We are wanting to transform whatever we are entering into our first tabstop (our variable name from up above), so we list &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;If we were transforming a variable instead of a tabstop input, we would put the variable name here instead.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So the answer to our question 1: &lt;strong&gt;Tabstop 1's input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Regex&lt;/strong&gt; - &lt;em&gt;What part is being transformed?&lt;/em&gt;&lt;/u&gt;&lt;br&gt;
If you are unfamiliar with regex syntax, there are some resources listed at the bottom of this post that might be helpful. For now, just know that this particular expression &lt;code&gt;(.*)&lt;/code&gt; indicates that we are searching within our tabstop input string for any characters in any combination; aka: return the whole string.&lt;/p&gt;

&lt;p&gt;So the answer to question 2 is: &lt;strong&gt;&lt;em&gt;All&lt;/em&gt; of Tabstop 1's input&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An important thing to note here before moving on is that the use of parentheses around the entire regex means that it is all part of the same regex "capture" – the first capture to be specific. This is important, because the &lt;strong&gt;format&lt;/strong&gt; section cares about captures and capture order.&lt;/p&gt;

&lt;p&gt;Again, if regex and captures are foreign to you, don't worry about it too much for this example. You can think of regex/captures this way: regex is a way to search a string for specific substrings, and captures are ways to further break those substrings into chunks that can be referenced. Here, the whole regex is grouped as a single chunk.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Format&lt;/strong&gt; - &lt;em&gt;How is it being transformed?&lt;/em&gt;&lt;/u&gt;&lt;/p&gt;

&lt;p&gt;Format references the results/captures from our regex and can act upon captures individually. Depending on the change being made, format can have the following syntaxes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Format Syntax&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;insertion&lt;/strong&gt;: &lt;code&gt;$«int»&lt;/code&gt; or &lt;code&gt;${«int»}&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;method&lt;/strong&gt;: &lt;code&gt;${«int»:/«method»}&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;conditional insertions&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if/else &lt;code&gt;${«int»:?«if insertion»:«else insertion»}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;if &lt;code&gt;${«int»:+«if insertion»}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;else &lt;code&gt;${«int»:-«else insertion»}&lt;/code&gt; or &lt;code&gt;${«int»:«else insertion»}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Above, "int" is the capture number being acted upon, "method" is the change being applied, and "if/else insertion" are strings to be inserted if the regex/capture does or does not return a match respectively.&lt;/p&gt;

&lt;p&gt;This can be quite a lot to get into, so let's limit our scope to our example. Recall that our format above looks like this:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;${1:/capitalize}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So our format appears to be calling a method of "capitalize" on capture number 1.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Sidenote:&lt;/em&gt; It would be easy to confuse the "1" here for referencing our tabstop $1, but they are entirely unrelated. In format, "1" indicates that this format is acting on the first capture in our regex. Note that if you wish to act on the entire regex collectively, you can list an int of "0" in your format. In our example, we only have one capture, and it is the entirety of our regex, so we could technically use "0" or "1".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The methods listed in the VS Code documentation are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;/upcase&lt;/strong&gt; - converts string to upper case&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;/downcase&lt;/strong&gt; - converts string to lower case&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;/capitalize&lt;/strong&gt; - capitalizes first character of string&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;/camelcase&lt;/strong&gt; - converts snake_case to camelCase&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;/pascalcase&lt;/strong&gt; - converts snake_case to PascalCase (aka upper-camelcase)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So our format of &lt;code&gt;${1:/capitalize}&lt;/code&gt; takes the first capture and capitalizes the first letter. This is exactly what we were aiming for!&lt;/p&gt;

&lt;p&gt;The answer to our third question then is: &lt;strong&gt;First Letter is Capitalized&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Recap
&lt;/h2&gt;

&lt;p&gt;That was a fairly in-depth look, so let's zoom back out to look at our snippet, and see if the pieces make more sense to us now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"const [$1, set${1/(.*)/${1:/capitalize}/}] = useState()"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bringing it back to our questions, we:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;What?&lt;/strong&gt; - &lt;code&gt;1&lt;/code&gt; - are taking the input from tabstop 1&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part?&lt;/strong&gt; - &lt;code&gt;(.*)&lt;/code&gt; - are modifying the whole input string&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Changes?&lt;/strong&gt; - &lt;code&gt;${1:/capitalize}&lt;/code&gt; - capitalize the first letter of that string&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;And...?&lt;/strong&gt;&lt;code&gt;&lt;/code&gt; and are done&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The result is a snippet which lets you type a variable one time, and as soon as you tab out of the first tabstop (you must tab out!) the second occurrence will adjust its capitalization automatically!&lt;/p&gt;

&lt;p&gt;It seems like a lot of work for something very small, but the more familiar you can become with snippet syntax, regex, format, etc, the easier it will become to implement.&lt;/p&gt;

&lt;p&gt;This is a complex topic, and this single use-case could only cover so much. I recommend looking through the resources below if you want to look into this further.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Snippets&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://code.visualstudio.com/docs/editor/userdefinedsnippets"&gt;Official VS Code Snippets Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://macromates.com/manual/en/snippets"&gt;TextMate Snippet Syntax Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Regex&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"&gt;Regular Expressions Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://regex101.com/"&gt;Regex101 - tool for testing regex&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jex.im/regulex/"&gt;Regulex - tool for visualizing regex expressions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>vscode</category>
      <category>snippets</category>
      <category>productivity</category>
      <category>regex</category>
    </item>
    <item>
      <title>Programming "Natural" Idle Character Animations</title>
      <dc:creator>ArkfulDodger</dc:creator>
      <pubDate>Wed, 16 Mar 2022 02:40:22 +0000</pubDate>
      <link>https://dev.to/arkfuldodger/programming-natural-idle-character-animations-4l0g</link>
      <guid>https://dev.to/arkfuldodger/programming-natural-idle-character-animations-4l0g</guid>
      <description>&lt;p&gt;When you create animations for a character, one of the key animations you should consider is the &lt;strong&gt;idle animation&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Idle Animation&lt;/strong&gt; - animation  that occurs when the character is not performing actions&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The purpose of an idle animation is to keep the character feeling "alive" even when they aren't &lt;em&gt;doing&lt;/em&gt; anything. Having excellent animation assets can help with creating this illusion, but any animation run on a loop (as our idle animation will be) is bound to feel artificial once the eye catches on to the repetitive pattern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Below, we are going to explore how to achieve more "natural" idle behavior by introducing purposeful randomness into our code.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Assumptions for This Walkthrough
&lt;/h2&gt;

&lt;p&gt;For this, we are going to assume we have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;animation assets (we will use two)&lt;/li&gt;
&lt;li&gt;a way to invoke the animations in our code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While the method you use for the above may vary drastically based on the game engine/app/extension you use, the logic we will explore in how/when to call these animations is transferrable.&lt;/p&gt;

&lt;p&gt;Our code examples below will be in JavaScript.&lt;/p&gt;




&lt;h2&gt;
  
  
  Examining Idle Animation Structure
&lt;/h2&gt;

&lt;p&gt;A common structure for an idle animation loop is to have a primary looped behavior which may be broken up by intermittent behaviors.&lt;/p&gt;

&lt;p&gt;Examine the cat gif below as an example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;looped behavior&lt;/strong&gt;: tail swish&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;intermittent behavior&lt;/strong&gt;: yawn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptl6t09cn8nhqddzx4i4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptl6t09cn8nhqddzx4i4.gif" alt="pixelated cat gif on a loop of swish, swish, yawn"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What you will also notice from this image is that you can very quickly catch on to the fixed pattern (2 swish, 1 yawn, repeat), so while it is more active than a static sprite, there is no illusion of it being "alive" as is our goal.&lt;/p&gt;




&lt;h2&gt;
  
  
  Creating the Basic Loop
&lt;/h2&gt;

&lt;p&gt;Let's imagine we start with the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="c1"&gt;// interval in milliseconds to run animation&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runAnimation&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;animateSwish&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// invokes our given tail swish animation&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;runAnimation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;interval&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// invokes animation every interval&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;setInterval() invokes a callback function every interval in milliseconds. Here, we have set it to run every 3 seconds, at which point it will call runAnimation (which we have told to invoke our given tailSwish animation). The resulting behavior will be to have our cat image swish its tail every three seconds.&lt;/p&gt;

&lt;p&gt;But we also want it to yawn, per our gif. So below we add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;// creates a counter&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yawnInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="c1"&gt;// sets count on which we will yawn&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runAnimation&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// if not yet to our yawn Interval, Swish&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;yawnInterval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="c1"&gt;// increment our count&lt;/span&gt;
        &lt;span class="nf"&gt;animateSwish&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="c1"&gt;// if at/above our yawn interval, Yawn&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;// resets swish counter&lt;/span&gt;
        &lt;span class="nf"&gt;animateYawn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// invokes our given yawn animation&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;runAnimation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;interval&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This successfully brings us to the point in our gif above where we have our looping swish punctuated by yawns at definite, repeated intervals.&lt;/p&gt;




&lt;h2&gt;
  
  
  Implementing Randomness
&lt;/h2&gt;

&lt;p&gt;Right now, our cat will always yawn on every 3rd loop. However, we can use Math.random() to randomly drop in a yawn at intervals within a range of our choosing.&lt;/p&gt;

&lt;p&gt;First, decide the &lt;em&gt;minimum&lt;/em&gt; number of loops after a yawn until our cat should be able to yawn again. &lt;strong&gt;This is subjective!&lt;/strong&gt; Ask yourself: would it look unnatural for our cat to yawn immediately after just yawning? &lt;em&gt;Probably.&lt;/em&gt; Let's say 2, so that our yawn will (at earliest) take place on the second loop after the last yawn.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let yawnIntMin = 2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next, set the &lt;em&gt;maximum&lt;/em&gt; loops that should pass between yawns. We know we want the behavior to take place at some point, so what is the longest we want to wait before having the cat yawn? For now, we'll say yawn on the 5th loop at latest.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let yawnIntMax = 5&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, we can use these to create a function that will return a random number between these two numbers (inclusive).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getRandomYawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;numberRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMax&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the +1 is important because Math.random is not inclusive of our max&lt;/span&gt;
    &lt;span class="nx"&gt;randomRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;numberRange&lt;/span&gt; &lt;span class="c1"&gt;// random decimal between 0 and 4 (not inclusive)&lt;/span&gt;
    &lt;span class="nx"&gt;randomInt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomRange&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// our decimal rounded down to an int (0, 1, 2, or 3 max)&lt;/span&gt;
    &lt;span class="nx"&gt;yawnInt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomInt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt; &lt;span class="c1"&gt;// add the min back in so we are in the desired range&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;yawnInt&lt;/span&gt; &lt;span class="c1"&gt;// in this example (2, 3, 4, or 5 max)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our entire function can be refactored to be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getRandomYawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;yawnIntMax&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's put this back in our main function so that every time our cat yawns, it will wait a random number of loops (within our defined range) before yawning again!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yawnInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getRandomYawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// set initially&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runAnimation&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;yawnInterval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
        &lt;span class="nf"&gt;animateSwish&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="nx"&gt;yawnInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getRandomYawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// set new&lt;/span&gt;
        &lt;span class="nf"&gt;animateYawn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;runAnimation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;interval&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our cat will yawn at unpredictable (more natural-feeling) intervals, while our min and max ensures that they won't yawn either too frequently or not frequently enough.&lt;/p&gt;




&lt;h2&gt;
  
  
  Building on the Concept
&lt;/h2&gt;

&lt;p&gt;This is the basic idea behind how to use code to create more "natural" behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decide the bounds within which a behavior feels natural, and allow the behavior to randomly occur within that range.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can implement this in many ways. So far, we have made it so that our cat will break up its tail swishes with yawns. However, note that our cat is still executing each behavior in unnaturally exact 3-second intervals.&lt;/p&gt;

&lt;p&gt;A next step could be to turn that interval at which behavior occurs into a variable itself, which could then be set to a random number of milliseconds within its own predetermined range. See below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// code governing getting the behavior interval (in milliseconds)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;behaviorIntMin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;behaviorIntMax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getRandomBehaviorInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;intervalSeconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;behaviorIntMax&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;behaviorIntMin&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;behaviorIntMin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;intervalSeconds&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// code governing getting the yawn interval (in loops)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getRandomYawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;yawnIntMax&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;yawnIntMin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// code to call animations&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;yawnInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getRandomYawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runAnimation&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;yawnInterval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
        &lt;span class="nf"&gt;animateSwish&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="nx"&gt;yawnInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getRandomYawnInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;animateYawn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;behaviorInterval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getRandomBehaviorInterval&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;runAnimation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;behaviorInterval&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="c1"&gt;// invoking our final function&lt;/span&gt;
&lt;span class="nf"&gt;runAnimation&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://arkfuldodger.github.io/flatiron-blog01-idle-animations/" rel="noopener noreferrer"&gt;View this code in action here!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The link above shows this code being used to animate our cat. You are encouraged to use the developer tools on that page to see the count, yawn interval, behavior interval, and animation calls logged as they happen to see how our randomization is working under the hood.&lt;/p&gt;

&lt;p&gt;In addition to the variables and function for getting our random behavior Interval, note that we are now calling setTimeout from &lt;em&gt;within&lt;/em&gt; our runAnimation function, feeding in runAnimation recursively as the callback.&lt;/p&gt;

&lt;p&gt;We were able use setInterval earlier when the behavior interval was (as the name says) &lt;em&gt;set&lt;/em&gt;. Now that the interval needs the freedom to be different every time, each invocation of runAnimation is going to trigger the next animation and then schedule the next call to runAnimation using our setTimeout method.&lt;/p&gt;

&lt;p&gt;This is one solution for creating this loop in Javascript, and the language/engine you are using will determine the easiest and most efficient way to do this in your own project.&lt;/p&gt;




&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;Depending on the assets (animations) at your disposal, there are many ways to utilize these ideas. Additionally, you are not bound to &lt;em&gt;truly&lt;/em&gt; random sequences of behavior. For instance, a stretching animation might be &lt;em&gt;more&lt;/em&gt; likely to occur directly following a yawning animation than it would otherwise, which delves into weighted random choices.&lt;/p&gt;

&lt;p&gt;How (and if) you ultimately implement idle animations in your projects is up to you, but understanding how to structure randomness within otherwise static loops is a great tool to have in your belt. Next time you play a game, keep an eye out for idle character animations to see how this has been implemented out in the wild!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>gamedev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
