Skip to content

Instantly share code, notes, and snippets.

View gist:4156de0301a326d7d497

Lodash

  1. _() vs _.chain()
> _([1,2,3,4,5]).map(function (x) { return x * x }).first(3).value()
[ 1, 4, 9 ] // the same if first(3)
> _.chain([1,2,3,4,5]).map(function (x) { return x * x }).first(3).value()
[ 1, 4, 9 ] // the same if first(3)
> _.chain([1,2,3,4,5]).map(function (x) { return x * x }).first()
@rorcraft
rorcraft / .slate
Created Jun 26, 2014
Slate config
View .slate
# This is the default .slate file.
# If no ~/.slate file exists this is the file that will be used.
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
# Resize Bindings
bind right:alt;ctrl resize +10% +0
bind left:alt;ctrl resize -10% +0
@rorcraft
rorcraft / gist:11407295
Created Apr 29, 2014
node module structure
View gist:11407295
// 1. bind every function
function foo(locale) {
return locale + '-foo';
}
module.exports = function helper(locale) {
return {
foo: foo.bind(null, locale)
}
@rorcraft
rorcraft / gulp-cwebp.js
Last active Aug 29, 2015
gulp plugin for cwebp, doesn't require imagemagick.
View gulp-cwebp.js
var through = require('through2')
, gutil = require('gulp-util')
function cwebp() {
var Webp = require('cwebp')
, File = require('vinyl')
return through.obj(function (file, enc, cb) {
this.push(file)
if (file.isBuffer()) {
View jamesgolick-ruby
brew update
brew tap homebrew/dupes
brew install apple-gcc42
export CC=gcc-4.2
curl https://gist.github.com/rorcraft/8815129/raw/f184726d7dd8d306d6f63acd97c39bb8ea6dbb84/jamesgolick-ruby > ~/.rbenv/plugins/ruby-build/share/jamesgolick
rbenv install jamesgolick
View gist:8745618
var assert = require('assert');
var helpers = {
view: function() {
return "viewing: " + this.msg;
}
}
// jade
// "h1= view()"
// compiled jade
View gist:8117308
package main
import "fmt"
import "math/rand"
import "time"
func tree(width int, level int) {
rand.Seed(time.Now().UnixNano())
full_width := width + (2 * level)
tree_level(1, width, full_width)
View gist:7967310
lambda { |x| puts "#{x}.call(%q(#{x}))" }.call(%q(lambda { |x| puts "#{x}.call(%q(#{x}))" }))
View paths.rb
module ActionController
module Railties
module Paths
def self.with(app)
Module.new do
define_method(:inherited) do |klass|
super(klass)
if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_helpers_paths) }
paths = namespace.railtie_helpers_paths
@rorcraft
rorcraft / gist:6598302
Last active Dec 23, 2015
dalli race_condition_ttl
View gist:6598302