Skip to content

Instantly share code, notes, and snippets.

@mritzco
Last active January 18, 2018 08:59
Show Gist options
  • Save mritzco/0055ff13e67923bd5bffe89bdae14033 to your computer and use it in GitHub Desktop.
Save mritzco/0055ff13e67923bd5bffe89bdae14033 to your computer and use it in GitHub Desktop.
Snippets for atom
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing 'snip' and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
# 'Console log':
# 'prefix': 'log'
# 'body': 'console.log $1'
#
# Each scope (e.g. '.source.coffee' above) can only be declared once.
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# https://atom.io/docs/latest/using-atom-basic-customization#cson
'.source.js':
'inferno component':
'prefix': 'component'
'body': """
// src/components/$1/$1.js
import Inferno from 'inferno';
import Component from 'inferno-component';
// import './$1.css';
// import Inferno, { linkEvent } from 'inferno';
class $1 extends Component {
// constructor() {
// super();
// }
render(props, state) {
return (
// Some ugly JSX
);
}
}
export default $1;
"""
'inferno import':
'prefix': 'import'
'body': """
import $1 from './$1/$1';
"""
'jquery onload':
'prefix': 'onload'
'body': """
$(function() {
console.log( 'ready!' );
});
"""
'log':
'prefix': 'log'
'body': 'console.log($1);'
'Object has':
'prefix': 'has'
'body': 'hasOwnProperty("$1")'
'Object own':
'prefix': 'props'
'body': 'Object.getOwnPropertyNames($1);'
'Tests Describe':
'prefix': 'desc'
'body': """
describe('$1', function() {
$2
});
"""
'Tests it':
'prefix': 'it'
'body': """
it('${1:expects }',function(done) {
$2
done();
});
"""
'Tests expects':
'prefix': 'xp'
'body': 'expect($1).to.'
'Tests expects equal':
'prefix': 'xeq'
'body': 'expect($1).to.equal();'
'Tests expects deep equal':
'prefix': 'xdeep'
'body': 'expect($1).to.deep.equal();'
'Tests expects true':
'prefix': 'x1'
'body': 'expect($1).to.be.true;'
'Tests expects false':
'prefix': 'x0'
'body': 'expect($1).to.be.false;'
'Tests expects haveOwnProperty':
'prefix': 'xhas'
'body': 'expect($1).to.haveOwnProperty();'
'Tests after':
'prefix': 'after'
'body': """
after(function(done) {
$1
});
"""
'Tests expects matches count to equal':
'prefix': 'xpmc'
'body': 'expect($1.match(/$2/g).length).to.equal($3);'
'Tests before':
'prefix': 'before'
'body': """
before(function(done) {
$1
});
"""
'Comment block':
'prefix': 'cc'
'body': '/* $1 */'
'Javascript module':
'prefix': 'mod'
'body': """
(function() {
'use strict';
/* variables & includes */
var methods = {},
priv = {};
/* private functions and public methods */
$1
module.exports = methods;
}());
"""
'Javascript module B':
'prefix': 'modObj'
'body': """
var module = (function () {
// private variables and functions
var foo = 'bar';
// constructor
var module = function () {
};
// prototype
module.prototype = {
constructor: module,
something: function () {
}
};
// return module
return module;
})();
var my_module = new module();
"""
'callback for error only':
'prefix': 'cbe'
'body': """
function(err) {
$1
}
"""
'callback standard':
'prefix': 'cb'
'body': """
function(err, data) {
$1
}
"""
'chai':
'prefix': 'chai'
'body': """
'use strict'
var chai = require('chai');
var expect = chai.expect;
"""
'Array delete':
'prefix': 'adel'
'body': 'splice($1,1);'
'Array delete at index':
'prefix': 'adelat'
'body': 'splice($1.indexOf(),1);'
'Array insert':
'prefix': 'arrins'
'body': 'Array.prototype.splice.apply($1, [idx, 0].concat( /*other array*/ ));'
'Array copy':
'prefix': 'arrcopy'
'body': '.slice();'
'chalk':
'prefix': 'chalk'
'body': 'console.log(chalk.$1(""), $2);'
'throw':
'prefix': 'throw'
'body': ' throw "$1"'
'timeloop':
'prefix': 'timeloop'
'body': """
(function myLoop () {
setTimeout(function () {
//Your code goes here
if (condition_for_running) myLoop(); // call loop again if condition is valid
}, 200)
})();
"""
'exit':
'prefix': 'exit'
'body': 'process.exit();'
'ng apply':
'prefix': 'apply'
'body': """
$scope.$apply(function() {
$1
});
"""
'time':
'prefix': 'time'
'body': """
$timeout(function() {
$1
}, $2 );
"""
'debug':
'prefix': 'debug'
'body': 'debugger'
'case':
'prefix': 'case'
'body': """
case $1:
break;
"""
'Object keys':
'prefix': 'keys'
'body': 'Object.keys($1)'
'Object keys length':
'prefix': 'olen'
'body': 'Object.keys($1).length'
'Object forEach':
'prefix': 'oeach'
'body': """
Object.keys($1).forEach(function(key) {
});
"""
'Array forEach':
'prefix': 'each'
'body': """
forEach(function(item) {
$1
});
"""
'asyncloop':
'prefix': 'asyncloop'
'body': """
var countdown = $1.length;
for (let i = 0, len = $1.length; i < len; i++) {
/*jshint -W083 */
obj.method(params, function (err, data) {
if (err) grunt.log.error(err);
if (--countdown === 0) {
done();
}
});
}
"""
'Test long time test':
'prefix': 'longtest'
'body': 'this.timeout(${1:8000});'
'Methods function':
'prefix': 'mfn'
'body': """
methods.$1 = function $1() {
};
"""
'is Defined':
'prefix': 'def'
'body': '"undefined" !== typeof'
'args2array':
'prefix': 'args'
'body': 'args = Array.prototype.slice.call(arguments)'
'Prettify JSON with spaces':
'prefix': 'prettyJson'
'body': 'JSON.stringify($1,null,2)'
'Grunt variable in string':
'prefix': '\'<%'
'body': '\'<%= $1 %>'
'Function with optional options':
'prefix': 'funopt'
'body': """
function $1(options, callback) {
if (!callback) {
callback = options;
options = {};
}
options = _.merge({}, defaults, options)
}
"""
'Options and defaults':
'prefix': 'opts'
'body': 'let opts = Object.assign({ key: "value"}, options );'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment