Skip to content

Instantly share code, notes, and snippets.

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
@Spaceghost
Spaceghost / mirror_test.sh
Created Jan 14, 2021 — forked from lox/mirror_test.sh
A bash script to select the fastest ubuntu apt geo-mirror
View mirror_test.sh
#!/bin/bash -e
# mirror_test.sh
# benchmarks closest ubuntu mirrors and outputs them in speed order
# bash -c "$(curl -fsSL https://gist.githubusercontent.com/lox/9152137/raw/mirror_test.sh)"
RELEASE=$(lsb_release -c -s 2>/dev/null || echo 14.04)
MIRRORS=$(curl -s http://mirrors.ubuntu.com/mirrors.txt)
TESTFILE="dists/$RELEASE/main/binary-amd64/Packages.bz2"
TIMEOUT=1
@Spaceghost
Spaceghost / smux.sh
Created Oct 3, 2020 — forked from hirschnase/smux.sh
autossh combined with tmux for a mosh like behaior
View smux.sh
function smux {
AUTOSSH_POLL=10
AUTOSSH_PORT=$(awk 'BEGIN { srand(); do r = rand()*32000; while ( r < 20000 ); printf("%d\n",r) }' < /dev/null)
#AUTOSSH_GATETIME=30
#AUTOSSH_LOGFILE=autossh.$HOST.log
#AUTOSSH_DEBUG=yes
#AUTOSSH_PATH=/usr/local/bin/ssh
export AUTOSSH_POLL AUTOSSH_LOGFILE AUTOSSH_DEBUG AUTOSSH_PATH AUTOSSH_GATETIME AUTOSSH_PORT
@Spaceghost
Spaceghost / how to install entware on ARM.md
Last active Aug 29, 2015 — forked from dreamcat4/how to install entware on ARM.md
Install entware on ARM based router eg tomato / ddwrt / asus-merlin cfw
View how to install entware on ARM.md
View gist:832674f2190ef547b340
module Prelaunchr
module Twilio
class Client
def self.configure(&block)
Twilio.configure(&block)
end
def initialize
@client = Twilio::REST::Client.new
@Spaceghost
Spaceghost / functions.sh
Created Jan 20, 2015
Idempotence in your path.
View functions.sh
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
}
@Spaceghost
Spaceghost / gist:bd4a3ec584add69b99da
Created Jan 10, 2015
github.com host key fingerprint art
View gist:bd4a3ec584add69b99da
+--[ RSA 2048]----+
| . |
| + . |
| . B . |
| o * + |
| X * S |
| + O o . . |
| . E . o |
| . . o |
| . . |
View README.md

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
View gist:e2f84189ea46e3abd3bc
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
View README.md

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.

View each_with_object.rb
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