Skip to content

Instantly share code, notes, and snippets.

View nilz3ro's full-sized avatar
🧃

nil nilz3ro

🧃
View GitHub Profile
@nilz3ro
nilz3ro / reverse.js
Last active May 29, 2019 15:31
es6, recursion, rest and spread operators, destructuring and default parameter value.
'use strict';
const reverse = (enumerable, sorted=[]) => {
let [head, ...tail] = enumerable;
return head === undefined
? sorted.join('')
: reverse(tail, [head, ...sorted])
;
}
@nilz3ro
nilz3ro / flatten.js
Last active December 1, 2015 18:38
es6 recursion
'use strict';
const flatten = (...args) => {
let [head, ...tail] = args;
return head === undefined
? []
: ( Array.isArray(head) ? [...flatten(...head), ...flatten(...tail)] : [head, ...flatten(...tail)] )
;
}
@nilz3ro
nilz3ro / bouncyCastle.js
Last active December 14, 2015 16:36
npm-scripts compatible way to exit if you are not using the supported node version for your project.
(function() {
var message = '';
var exitCode = 0;
var supportedNodeVersion = 'v0.10.36';
if(process.version === supportedNodeVersion) {
message = 'You are using the supported node version for this project, Continuing.';
}
else {
message = 'You must use node v0.10.36 while developing this project. Exiting.';
@nilz3ro
nilz3ro / brew.txt
Last active September 21, 2016 02:09
ack
autoconf
automake
aws-elasticbeanstalk
awscli
bdw-gc
boot-clj
cairo
chgems
chrome-cli
@nilz3ro
nilz3ro / iso.countries.js
Last active November 18, 2023 05:38
Write json file
// Paste this in a node v4.x REPL.
// let iso = require('./iso.countries.js');
// iso.writeCountryJsonFile('test.js', (country) => { let o={}; o['name'] = country['name']; o['ISO3166-1-Alpha-2'] = country['ISO3166-1-Alpha-2']; o['code'] = country['ISO3166-1-Alpha-2']; o['Dial'] = country['Dial']; return o;});
'use strict';
let fs = require('fs');
let countries;
const writeCountryJsonFile = (outputFilename, mapFunction) => {
@nilz3ro
nilz3ro / max-integer-by-bit.go
Created December 21, 2015 07:15
Wondering what the maximum integer value is in the go language? Wonder no more!!!
package main
import "fmt"
const (
MaxInt8 = 1<<7 - 1 // 127
MinInt8 = -1 << 7
MaxInt16 = 1<<15 - 1 // 32_767
MinInt16 = -1 << 15
MaxInt32 = 1<<31 - 1 // 2_147_483_647
MinInt32 = -1 << 31
set -g default-terminal "screen-256color"
set -g status-bg white
set -g status-fg black
set -g pane-border-style fg=black
set -g pane-active-border-style fg=white
set -g pane-active-border-style bg=black
# remap prefix to Control + a
set -g prefix C-a
# bind 'C-a C-a' to type 'C-a'
# Path to your oh-my-zsh installation.
export ZSH=/Users/abuddington/.oh-my-zsh
source /usr/local/share/chruby/chruby.sh
source /usr/local/opt/chruby/share/chruby/auto.sh
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
alias be="bundle exec"
alias gs="git status"
@nilz3ro
nilz3ro / ws.md
Last active February 27, 2016 04:36
WebSocket Notes

Notes

WebSocket Protocol is an Application Layer protocol that enables a client and server to send and receive messages simultaneously through a full duplex stream over one TCP/IP connection on port 80 or 443.

Default WebSocket protocol client request, and server response:

  • send HTTP/1.1 GET
    GET /chat HTTP/1.1
    
    Host: server.example.com
    
@nilz3ro
nilz3ro / lambda.js
Created July 14, 2016 02:01
lambda expressions / currying in es6
((n) => ((y) => y*n))
// [Function]
((n) => ((y) => y*n))(9)
// [Function]
((n) => ((y) => y*n))(9)(3)
// 27