Skip to content

Instantly share code, notes, and snippets.

View Spaceghost's full-sized avatar
👻
Building distributed and decentralized systems that run in the browser

Johnneylee Jack Rollins Spaceghost

👻
Building distributed and decentralized systems that run in the browser
View GitHub Profile

Benchmarking #map

#map(&:id) is faster than a block.
#map is faster than #each_with_object when doing roughly the same work.

In short, this might make you want to extract more public methods, even if you use them in decorators or proxy objects, that you can call with Symbol#to_proc.

require 'benchmark/ips'
User = Struct.new(:id, :stuff)
a = Array.new(1000) { |i| User.new(i, stuff: rand(1000)) }
Benchmark.ips do |x|
x.report('#inject assign&return') do
a.inject({}) { |memo, i| memo[i.id] = i.stuff; memo }
end
x.report('merge') do
@Spaceghost
Spaceghost / pr.md
Last active August 29, 2015 14:11 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@Spaceghost
Spaceghost / .README.md
Last active August 29, 2015 14:11 — forked from gnarf/..git-pr.md

Install

Either copy the aliases from the .gitconfig or run the commands in add-pr-alias.sh

Usage

Easily checkout local copies of pull requests from GitHub remotes:

  • git pr 4 - creates local branch pr/4 from the origin remote and checks it out
  • git pr 4 upstream - creates local branch pr/4 from upstream remote and checks it out
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.macports.gpg-agent</string>
<!-- Please uncomment on 10.4; OnDemand doesn't work properly there. -->
<!--
<key>OnDemand</key>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.gnupg.gpg-agent</string>
<key>ProgramArguments</key>
<array>
<string>start-gpg-agent</string>
tim0thy:phoenix-demo32 pipework$ java -jar phoenix_demo32.jar
Exception in thread "main" scala.MatchError: osx (of class java.lang.String)
at com.sg.pnx.util.SysUtil$.nativeLibs(SysUtil.scala:41)
at com.sg.pnx.util.SysUtil$.checkForNativeLibs(SysUtil.scala:88)
at com.sg.pnx.util.SysUtil$.loadNativeLibs(SysUtil.scala:80)
at com.sg.pnx.util.InitUtil$.init(InitUtil.scala:17)
at com.sg.pnx.Game$.delayedEndpoint$com$sg$pnx$Game$1(Game.scala:17)
at com.sg.pnx.Game$delayedInit$body.apply(Game.scala:13)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
# JS config for NVIDIA SHIELD
# Axes:
# -----
# 1 Left stick H
# 2 Left stick V
# 3 Left trigger
# 4 Right stick H
# 5 Right stick V
# 6 Right trigger
# 7 Pad H
commit 95bcc8ac6463e63001b33094ede2e21796da6c23
Author: Johnneylee Jack Rollins <Johnneylee.Rollins@gmail.com>
Date: Mon Jun 30 07:17:59 2014 -0700
Add Callable and Bindable for services/controllers
* Callable depends on the extending class implementing #call as an
instance method. Another instance method name might be preferable, I
don't know. I've even seen fun dynamic things like `extend
Callable.call_method(:execute)`
class UserCreator
def initialize(listener)
@listener = listener
end
def create(attributes)
user = User.new(attributes)
if user.save
# send email