Skip to content

Instantly share code, notes, and snippets.

@yannbertrand
yannbertrand / Article.js
Created May 21, 2015 13:25
Example models
module.exports = {
attributes: {
title: {
type: 'text'
},
content: {
type: 'text'
},
@yannbertrand
yannbertrand / matches.json
Created May 21, 2015 13:30
2015 Rugby World Cup Fixtures
[
{
"matchNumber": 1,
"kickOff": "2015-09-18T20:00:00.000Z",
"pool": "A",
"teamA": "England",
"teamB": "Fiji",
"location": "Twickenham, London"
},
@yannbertrand
yannbertrand / json-stringify-tips.js
Last active August 29, 2015 14:24
JSON.stringify tips
var toto = {
foundation: 'Mozilla',
model: 'box',
week: 45,
transport: 'bus',
month: 7
};
JSON.stringify(toto);
// '{"foundation":"Mozilla","model":"box","week":45,"transport":"bus","month":7}'
@yannbertrand
yannbertrand / Preferences.sublime-settings
Last active August 29, 2015 14:24 — forked from benatkin/Global.sublime-settings
Hiding some folders from Sublime Text 3's Side Bar
// Place user-specific overrides in this file, to ensure they're preserved
// when upgrading
{
"folder_exclude_patterns": [".svn", ".git", ".hg", "CVS", "node_modules"]
}
@yannbertrand
yannbertrand / console-tips.js
Last active July 17, 2016 04:38
Some console tips
/**
* console.log
*/
console.log('Hello');
// → "Hello"
var hello = 'Hello';
console.log(hello);
// → "Hello"
@yannbertrand
yannbertrand / window-locations-tips.js
Last active August 29, 2015 14:25
Some window.location tips
// We are on page
// http://www.example.com:8080/search?q=devmo#test
console.log(window.location.href)
// → "http://www.example.com:8080/search?q=devmo#test"
console.log(window.location.origin)
// → "http://www.example.com:8080"
console.log(window.location.protocol)
@yannbertrand
yannbertrand / implode-explode.js
Last active April 6, 2017 13:36
How to implode/explode an array in JS?
// explode -> .split
console.log(['Hello', 'World'].join()) // ',' is optional
// → "Hello,World"
// implode -> .join
console.log('Hello,World'.split(','))
// → Array [ "Hello", "World" ]
@yannbertrand
yannbertrand / Naming things in programming
Created January 7, 2016 13:38
Some advices to apply good names for your programming entities
See http://fr.slideshare.net/pirhilton/how-to-name-things-the-hardest-problem-in-programming by @hilton
Summary of naming things badly :
- meaningless: foo
- too general: data
- too short: a
- too long: text_correction_by_editor
- abbreviated: acc (id is the only acceptable abbreviation)
- vague: InvoiceManager
- wrong: order
@yannbertrand
yannbertrand / angular-bullshit.js
Last active June 13, 2018 17:48
Bullshit code from Angular
$resource(a, b, {
getSomething: {
method: 'GET',
url: baseUrl + ':id' // work if you pass the `id` param in the parameters object
},
postSomething: {
method: 'POST',
url: baseUrl + ':id', // you need to add the next line to make it work for post requests (didn't try with other verbs)
params: { id: '@id' }
}
@yannbertrand
yannbertrand / better-index-of.js
Created January 18, 2016 10:15
Simplify the use of indexOf
// Array
var list = ['my', 'str', 'list'];
if (~list.indexOf('my')) {
console.log('the `list` array contains \'my\'');
}
if (!~list.indexOf('number')) {
console.log('the `list` array does not contain \'number\'');
}