Skip to content

Instantly share code, notes, and snippets.

@valentincognito
Last active March 12, 2020 05:43
Show Gist options
  • Save valentincognito/4a764401955e65bfa3bbb90100d20695 to your computer and use it in GitHub Desktop.
Save valentincognito/4a764401955e65bfa3bbb90100d20695 to your computer and use it in GitHub Desktop.
# 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:
# http://flight-manual.atom.io/using-atom/sections/basic-customization/#_cson
'.source.js':
'Console log':
'prefix': 'log'
'body': """
console.log(``)
"""
'Document ready':
'prefix': 'ready'
'body': """
$(function() {
console.log('ready')
})
"""
'On click event':
'prefix': 'oc'
'body': """
$('.class-name').click(function(e){
e.preventDefault()
})
"""
'Dynamic click event':
'prefix': 'doc'
'body': """
$('body').on('click', '.class-name', function(e) {
e.preventDefault()
})
"""
'Ajax':
'prefix': 'ajax'
'body': """
$.ajax({
url: '/',
type: 'POST',
data: {
field: value
},
success: function(data) {
console.log(data)
},
error: function (request, status, error) {
console.log('code: '+request.status+' error: '+error)
}
})
"""
'Get JSON':
'prefix': 'getjson'
'body': """
$.getJSON("data.json", function(json) {
console.log(json)
})
"""
'Fs readFile':
'prefix': 'fsread'
'body': """
fs.readFile('./public/data.json', (err, data) => {
if (err) throw err
let json = JSON.parse(data)
console.log(json)
})
"""
'Fs writeFile':
'prefix': 'fsWrite'
'body': """
fs.writeFile('./data.json', data, (err) => {
if (err) throw err
console.log('saved!')
})
"""
'Fs listFiles':
'prefix': 'fslist'
'body': """
const directoryPath = path.join(__dirname, 'public')
fs.readdir(directoryPath, function (err, files) {
if (err) throw err
files.forEach(function (file) {
console.log(file)
})
})
"""
'Random number':
'prefix': 'rand'
'body': """
Math.floor(Math.random() * 6) //random number from 0 to 5
"""
'Filter by a key value':
'prefix': 'filter'
'body': """
let item = array.find(function (obj) {return obj.key === "value"})
"""
'Blocking wait function':
'prefix': 'wait'
'body': """
function wait (ms) {
return new Promise(resolve => setTimeout(() => resolve(), ms))
}
"""
'Mongoose new entry':
'prefix': 'mongoNew'
'body': """
let record = new Record()
record.name = "value"
record.save(err => {
if (err)
res.json({status: 'error', err: err})
else
res.json({status: 'success', record: record})
})
"""
'Mongoose findById':
'prefix': 'mongoFindById'
'body': """
Model.findById(id, function (err, record) {
})
"""
'Form validation':
'prefix': 'validationOnSubmit'
'body': """
$('#my_form').submit(function(e) {
let validations = [
{
description: 'empty field',
status: $('.field').val().length != 0 ? true : false,
message: 'field xxx is empty'
}
]
let isFormValidated = true
for (let validation of validations) {
if (!validation.status) {
e.preventDefault()
alert(validation.message)
}
}
if (!isFormValidated) {
e.preventDefault()
}
})
"""
'.source.pug':
'Datetime helper':
'prefix': 'date'
'body': """
- let month = record.date.getMonth() + 1
td= month.toString().padStart(2, '0') + "/" + record.date.getDate().toString().padStart(2, '0') + "/" + record.date.getFullYear()
"""
'Select selected option':
'prefix': 'select'
'body': """
selected=(category._id.toString()==article.category ? true : false))
"""
'.source.css':
'Boilerplate':
'prefix': 'boilerplate'
'body': """
@import url('https://fonts.googleapis.com/css?family=Libre+Baskerville|Open+Sans:400,700');
*,
*:after,
*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html{height: 100%;font-family: 'Open Sans', sans-serif;font-size: 14px;font-weight: 400;word-break: keep-all;}
body{margin: 0px;color: #000;background-color: #fcfcfc;}
a {background-color: transparent;text-decoration: none;color: inherit;display: block;opacity: 1;transition: all 0.2s ease-in-out;}
a:active,
a:hover{outline: 0;text-decoration: none;color: inherit;}
/** helpers **/
.show{display: block;}
.hidden{display: none !important;}
.pull-left{float: left;}
.pull-right{float: right;}
.text-left{text-align: left;}
.text-right{text-align: right;}
.text-center{text-align: center;}
.block{display: block;}
.inline-block{display: inline-block;}
.clearfix:before,
.clearfix:after {content: "";display: table;}
.clearfix:after {clear: both;}
.clearfix {zoom: 1; /* ie 6/7 */}
/* helpers end */
/** common **/
.content{
position: relative;
margin: 0 auto;
padding: 40px;
}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment