Skip to content

Instantly share code, notes, and snippets.

View Ynote's full-sized avatar
🌻

Fanny Cheung Ynote

🌻
View GitHub Profile
@Ynote
Ynote / node-sauce-connect.coffee
Last active July 14, 2016 11:42
[Node] - Simple module for Sauce Connect
# modules
spawn = require('child_process').spawn
credentials = require('sauce-labs-credentials')
scPath = 'path/to/sc/bin'
R = require('ramda')
Q = require('q')
# global var
startDeferred = null
sc = null
@Ynote
Ynote / pairwise-array.js
Last active June 14, 2016 16:46
[Javascript] - Pairwise combinations of an array
var pairwise = function(arr)
{
if (arr.length < 2){ return []; }
var first = arr[0],
sliced = arr.slice(1),
getPair = function(x){ return [first, x]; }
pairs = sliced.map(getPair);
return pairs.concat(createPossibilities(sliced));
@Ynote
Ynote / forEach.js
Last active June 14, 2016 16:46
[Javascript] - forEach function implementation
function forEach(list, callback, endIndex)
{
if (!list instanceof Array) console.error('forEach method accepts an instanceof Array as first parameter!')
var end = endIndex || list.length - 1,
args = [[list, callback, endIndex], Array.prototype.slice.call(arguments, 3)],
args = args.reduce(function(a,b){ return a.concat(b); });
for(var i = 0; i <= end; i++)
{
@Ynote
Ynote / memozing-function.js
Last active June 14, 2016 16:47
[Javascript] - Power of two memozing function with closure
Function.prototype.memoized = function(key) {
this._values = this._values || {};
return this._values[key] !== undefined ?
this._values[key] :
this._values[key] = this.apply(this, arguments);
}
Function.prototype.memoize = function() {
var fn = this;
return function() {
@Ynote
Ynote / memoizing-currying-function.js
Last active June 14, 2016 16:47
[Javascript] - Add memoizing and currying function
var add = function() {
add.toString = function() {
console.log(add.total);
};
add.reset = function() {
add.total = 0;
return add;
};
@Ynote
Ynote / factorygirl-cheat-sheet.rb
Last active February 1, 2018 11:04
[Rails] - FactoryGirl cheat-sheet
# spec/fixtures/usernames.rb
USERNAMES = ['hermione.granger',
'ron.weasley',
'harry.potter',
'fred.weasley',
'georges.weasley',
'luna.lovegood',
'ginny.weasley',
'draco.malfoy',
'albus.dumbledore',
@Ynote
Ynote / tail-call-optimization.js
Last active October 18, 2022 13:33
[Javascript] - Tail-recursive factorial function
// This is just a short reminder of this great explanation:
// http://www.2ality.com/2015/06/tail-call-optimization.html
// not TCO
function factorial(n) {
if (n <= 0) return 1;
return n * factorial(n-1); // here, the main recursive call not in a tail position because of the `n` context.
}
@Ynote
Ynote / enable-apache-site.sh
Last active July 14, 2016 11:45
[CLI] - Enable sites with Apache
$ sudo -s # enable sudo on current user
$ a2ensite [conf-name] # enable site that are in sites-available
$ a2dissite [conf-name] # disable site that are in sites-available
$ /etc/init.d/apache2 reload # reload Apache
@Ynote
Ynote / atomic-css.html
Last active July 9, 2017 12:55
Medium - atomic CSS snippet
<h3 class="green bgr-grey text-h3 col-xs-12 col-6-md">
I love Kitten
</h3>
@Ynote
Ynote / BEM-methodology.html
Last active July 9, 2017 13:28
Medium - BEM methodology snippet
<div class="project-card">
<h4 class="project-card__title">Mon nouveau projet</h4>
<p class="project-card__description">Une description passionnante</p>
<a class="project-card__action project-card__action-primary">Découvrir</a>
<div>