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
<?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>
<?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>
@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
@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:

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

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.

Calculating -------------------------------------
#inject assign&return
290.000 i/100ms
merge 1.000 i/100ms
merge! 106.000 i/100ms
each_with_object 292.000 i/100ms
zenspider 298.000 i/100ms
pipework 299.000 i/100ms
-------------------------------------------------
#inject assign&return

Benchmarking ruby

The problem: Create a hash from an array of objects where the key is the object's #id and the value is the #stuff method.

Known/Suspected caveats:

  • Garbage collection might be happening, making the results lie.
  • Not exhaustive of ways to create a hash from an array
  • Not exhaustive of ways to call Benchmark.ips with code to test. (no strings yet)
  • Not able to manually change the number of iterations
@Spaceghost
Spaceghost / gist:bd4a3ec584add69b99da
Created January 10, 2015 02:28
github.com host key fingerprint art
+--[ RSA 2048]----+
| . |
| + . |
| . B . |
| o * + |
| X * S |
| + O o . . |
| . E . o |
| . . o |
| . . |
@Spaceghost
Spaceghost / functions.sh
Created January 20, 2015 04:03
Idempotence in your path.
idempotent_path_prepend() { # idempotent_path_append dir1 dir2 dir3 => dir1:dir2:dir3:$PATH
for ((i=$#; i>0; i--)); do ARG=${!i}
if [ -d "$ARG" ]; then # Only add to path if the path currently exists. Might remove.
PATH=${PATH//":$ARG"/} # delete any instances in the middle or at the end
PATH=${PATH//"$ARG:"/} # delete any instances at the beginning
export PATH="$ARG:$PATH" # prepend to beginning
fi
done
}