Skip to content

Instantly share code, notes, and snippets.

@rorcraft
rorcraft / gist:4156de0301a326d7d497
Last active January 18, 2016 22:42
Lodash notes.

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 / gist:8117308
Created December 24, 2013 20:02
Christmas tree
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)
@rorcraft
rorcraft / gist:7967310
Created December 15, 2013 01:03
Ruby Quine
lambda { |x| puts "#{x}.call(%q(#{x}))" }.call(%q(lambda { |x| puts "#{x}.call(%q(#{x}))" }))
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 December 23, 2015 07:08
dalli race_condition_ttl
#!/usr/bin/env bash
\. "${rvm_path}/scripts/functions/hooks/jruby"
export PROJECT_JRUBY_OPTS="-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -X-C"
if [[ "${rvm_ruby_string}" =~ "jruby" ]]
then
jruby_options_append "${PROJECT_JRUBY_OPTS[@]}"
else
@rorcraft
rorcraft / gist:5854221
Last active December 18, 2015 22:19
Xiaomi Mi2s Android vs iPhone iOS.

Xiaomi

build:

  • feels like iPhone 3G - plastic back, thicker than iPhone4 and above.
  • sturdy enough, but I'm worried if its dropped into water. iPhone is better sealed out of the box.
  • sits well on one hand without a case. iPhone built for adding a case.
  • screen - some weird uneven chemical spots, probably need to use a protector.
  • camera produces pretty high quality photos, auto focus could be slow.
  • battery, similar to iPhone4, slightly better.
  • wifi range, similar to iPhone4, not any better.
@rorcraft
rorcraft / gist:5784318
Last active December 18, 2015 12:39
ruby heredoc

Heredoc

  • auto indent
  • auto new line
<<GROCERY_LIST
  1. Salad mix 
  2. Strawberries 
 3. Cereal

HTTP Caching

  1. Cache by expiration time.
  2. Conditional Get by versioning.

Cache by expiration time.

Tells the client and intermediary cache what to cache.

HTTP 1.0:

@rorcraft
rorcraft / .cane
Created May 2, 2013 01:04
Custom CaneLintSpec
--no-doc
--no-abc
--style-glob {app,lib}/**/*.rb
--require spec/cane_lint_spec.rb
--check CaneLintSpec
--lint-spec-glob {app,lib}/**/*.rb