Skip to content

Instantly share code, notes, and snippets.

View jakeNiemiec's full-sized avatar
💭
A well-oiled toaster oven

Jake Niemiec jakeNiemiec

💭
A well-oiled toaster oven
  • Professional Worrier
  • Chicago, IL
View GitHub Profile
@HugoDF
HugoDF / join.js
Last active October 13, 2016 19:12
ES6 join implementation using recursion and destructuring
function join([ head, ...tail ], separator = ',') {
if (head === undefined && !tail.length) return '';
return tail.length ? head + separator + join(tail, separator) : head;
}
@HugoDF
HugoDF / filter.js
Last active October 14, 2016 14:22
ES6 filter implementation using recursion and destructuring
function filter([ head, ...tail ], fn) {
const newHead = fn(head) ? [ head ] : [];
return tail.length ? [ ...newHead, ...(filter(tail, fn)) ] : newHead;
}
@jakeNiemiec
jakeNiemiec / destructuring.js
Created November 7, 2016 23:33 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
var d3 = require('d3');
var jsdom = require("jsdom-little");
var React = require('react-native');
var { View, Text } = React;
var Svg = require('./Svg');
var parseDate = d3.time.format("%d-%b-%y").parse;
var D3Chart = React.createClass({
componentDidMount() {
// library or otherwise
// {
type Func<T, TResult> = (value: T) => TResult;
type Predicate<T> = Func<T, boolean>;
function compose<TIn, TMiddle, TOut>(f: Func<TMiddle, TOut>, g: Func<TIn, TMiddle>) {
return (value: TIn) => f(g(value));
}
import { action } from 'common/utils/redux/redux';
@action
export class Actions {
static types = {
set3d: Symbol('set3d')
};
static set3d(val) {
@HugoDF
HugoDF / reduce.js
Last active February 20, 2018 02:11
ES6 reduce implementation using recursion and destructuring
function reduce([ head, ...tail ], fn, initial) {
if(head === undefined && tail.length === 0) return initial;
if(!initial) {
const [ newHead, ...newTail] = tail;
return reduce(newTail, fn, fn(head, newHead));
}
return tail.length ? reduce(tail, fn, fn(initial, head)) : [ fn(initial, head) ];
}
@fortuity
fortuity / gist:468417
Created July 8, 2010 18:46
Options for "rails generate scaffold"
$ rails generate scaffold BusinessEntry content:string --no-stylesheets --no-fixture --no-test-framework --no-helper --pretend
invoke mongoid
create app/models/business_entry.rb
route resources :business_entries
invoke scaffold_controller
create app/controllers/business_entries_controller.rb
invoke haml
create app/views/business_entries
create app/views/business_entries/index.html.haml
create app/views/business_entries/edit.html.haml
import { Pipe } from 'angular2/core.js';
/**
* Map to Iteratble Pipe
*
* It accepts Objects and [Maps](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
*
* Example:
*
* <div *ngFor="#keyValuePair of someObject | mapToIterable">
@dsparks
dsparks / rcp_plot.R
Created November 16, 2012 11:54
Scraping and plotting RCP Polling Data
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("XML", "ggplot2", "lubridate", "reshape2", "scales")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Find your XML file from those listed at
# http://cdn.realclearpolitics.com/epolls/charts/
URL <- "http://cdn.realclearpolitics.com/epolls/charts/1171.xml"
parsedXML <- xmlParse(URL) # First pass