Skip to content

Instantly share code, notes, and snippets.

View therealklanni's full-sized avatar
👨‍💻
Learning Rust

Kevin Lanni therealklanni

👨‍💻
Learning Rust
View GitHub Profile
@therealklanni
therealklanni / unique.js
Created March 29, 2014 04:30
Get unique elements of an Array
// Another useful reducer
//
// Get unique values of a 1d array
function unique (a, b) {
if (a.indexOf(b) < 0) a.push(b)
return a
}
// Very simple use case
var arr = [1, 5, 7, 2, 2, 3, 3, 4, 5, 5, 52, 4, 1, 2, 9, 1, 3, 5]
@therealklanni
therealklanni / yc.js
Last active August 29, 2015 14:00
Memoized Y-combinator
// Y-combinator with memoization
var Yc = function (f, x) {
x = x || {};
return function () {
var y = JSON.stringify([].slice.call(arguments));
return x[y] || (x[y] = f(function (z) {
return Yc(f, x)(z);
}).apply(this, arguments));
@therealklanni
therealklanni / Node.sublime-build
Last active August 29, 2015 14:01
Sublime Text Node.js Buildtool
{
"cmd": ["/usr/local/bin/node", "$file"],
"selector": "*.js"
}
var fs = require('fs');
var rfs = fs.readFileSync;
var wfs = fs.writeFileSync;
var path = require('path');
var yaml = require('js-yaml');
var inquirer = require('inquirer');
var program = require('commander');
var version = require('./package.json').version;
program
from Crypto.Cipher import AES
from Crypto import Random
from libmproxy.flow import decoded
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]
def decrypt( enc, key ):
iv = enc[:16]
@therealklanni
therealklanni / 0_reuse_code.js
Last active August 29, 2015 14:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@therealklanni
therealklanni / accessors.md
Last active January 20, 2016 13:23
Demystifying Property Accessors

Examining the Object property accessor behavior

Consider the following scenario

function invert(color) {
  var lookup = {
    black: 'white',
    white: 'black'
 }
@therealklanni
therealklanni / ES6.sublime-build
Last active July 10, 2019 18:09
ES6 REPL in Sublime Text
{
"cmd": ["/usr/local/bin/babel-node $file"],
"shell": true,
"selector": "*.js"
}
@therealklanni
therealklanni / README.md
Last active January 27, 2020 17:07
Infinitely repeating arrays in JavaScript ... kind of

repeat(a) -> [a]

Inspired by Haskell, I wanted to see if I could replicate, using ES6 features, the repeat function:

repeat :: a -> [a]

So as you can see in repeat.js, I have done exactly that. However there are some caveats.

@therealklanni
therealklanni / using-git-guppy.md
Last active September 5, 2017 09:02
Supercharge your git hooks with gulp — Introducing git-guppy

Supercharge your git hooks with gulp

Introducing git-guppy

Automate your developer workflow with git-guppy. git-guppy allows you to add git-hooks to your project repository that are automatically installed when users clone and install your repository, so you won't have to worry about developers skipping essential workflow steps and bypassing your project guidelines.

Getting Started

So let's use a unit test scenario to illustrate an example. We're going to run unit tests before every commit (pre-commit hook) and reject the commit if the tests fail (giving the developer a chance to fix their tests before committing broken code).