Skip to content

Instantly share code, notes, and snippets.

View jamesmoriarty's full-sized avatar
🔮
0xc0000005

James Moriarty jamesmoriarty

🔮
0xc0000005
View GitHub Profile
@ntlk
ntlk / ruby_rgb_to_hsb.rb
Created November 21, 2011 19:18
converts RGB values to HSB
# Input rgb values 1...255
# based on http://forums.devshed.com/c-programming-42/rgb-to-hsv-conversion-rountine-162526.html
r = r / 255.0
g = g / 255.0
b = b / 255.0
max = [r, g, b].max
min = [r, g, b].min
delta = max - min
v = max * 100
@jboner
jboner / latency.txt
Last active May 18, 2024 15:58
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active May 18, 2024 11:00
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@stingh711
stingh711 / mount_ebs.sh
Created July 24, 2012 08:02
How to mount another EBS as /var on EC2 (ubuntu)
#!/bin/bash
#attach the EBS to /dev/sdf before running it
#format EBS
mkfs -t ext4 /dev/xvdf
#copy original /var to /dev/xvdf
mkdir /mnt/new
mount /dev/xvdf /mnt/new
cd /var
@gpfeiffer
gpfeiffer / extended_gcd.rb
Last active January 29, 2022 14:16
Extended Euclidean Algorithm in Ruby
#############################################################################
##
## extended_gcd.rb
##
## given non-negative integers a > b, compute
## coefficients s, t such that gcd(a, b) == s*a + t*b
##
def extended_gcd(a, b)
# trivial case first: gcd(a, 0) == 1*a + 0*0
@grindars
grindars / steam_bootstrap.sh
Created December 7, 2012 07:53
Steam installer for Debian
#!/bin/bash
#
# Steam installer for Debian wheezy (32- and 64-bit)
#
# Place into empty directory and run.
#
download() {
local url="$1"
local filename="$(basename "$url")"
@willurd
willurd / web-servers.md
Last active May 17, 2024 16:24
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@wsargent
wsargent / docker_cheat.md
Last active August 31, 2023 12:10
Docker cheat sheet
@andris9
andris9 / README.md
Last active December 29, 2022 02:38
Extremely simple HTTP proxy for changing Host: header Useful when proxying requests to virtual hosts that require Host: header to be set.

Setup reverse tunnel

Run the following in your client machine

ssh -R EXPOSED_PORT:localhost:SERVICE_PORT USER@HOST

Where

  • EXPOSED_PORT is the port exposed to the internet in the proxy server
  • SERVICE_PORT is the port your application is listening in your machine
#!/usr/bin/env ruby
#
# Syncs Ruby binstubs for ruby-communal-gems.
# Run this everytime you install a new Ruby, or when you install a new gem
# with a bin/ command. (ie, when you typically do rbenv rehash)
#
# See: https://github.com/tpope/rbenv-communal-gems/issues/5
#
require 'fileutils'