Skip to content

Instantly share code, notes, and snippets.

View kranrao's full-sized avatar

Kiran Rao kranrao

View GitHub Profile
@kranrao
kranrao / gist:8cc06d6956925092c93c
Last active August 29, 2015 14:12
Coding best practices
///// Scopes /////
- As little variables in global scope as possible
- iffes (immediately invoked function) are useful for creating closure and private variables
- Do not mutate inputs. But if you need to, be absolutely clear about it in your documentation
///// Closures /////
- Functions create new closure scopes
- A closure is a function object that retains ongoing access to the variables of the context it was created in (even after the outer function calls it was created within have returned)
@kranrao
kranrao / gist:d89015e4c57caba99415
Last active August 29, 2015 14:12
JS code snippets
/////// Example of using Regexp with match in order to find the number of vowels in a string ///////
var vowelCount = function(str) {
var vowels = str.match(/[aeiou]/gi);
// if str was 'hi there', vowels is equal to ['i', 'e', 'e']
return (vowels === null) ? 0 : vowels.length;
};
/////// Example of how to use call to bind 'this' to the correct execution context ///////
@kranrao
kranrao / gist:222fe544a9b0f05387fa
Last active August 29, 2015 14:12
Plugins and tools
///// Sublime Text 2 /////
- Tools -> Build System -> Node: Command + B runs javascript console
- Tools -> Build System -> JSHint: Command + B checks javascript best practice syntax
- JavaScriptNext: better syntax highlighter
- SublimeOnSaveBuild: runs selected build system (see above) on save
///// Ghost /////
- Blogging platform (npm start in ghost folder to launch)
@kranrao
kranrao / gist:a7245ceec19a686c6aee
Last active October 20, 2024 00:35
Keyboard shortcuts
///// Terminal /////
ls - list of files in directory
ls -a - list of *all files in directory
cd - move into directory
ls -a subl .bash_profile - terminal shortcut editor
mkdir [dir name] - make new directory
touch [file name] - make new file
mv [file name] [new file name] - changes file name
cp [file name] - copies file or directory