Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
asm.block do
# low nybble of nth byte
movzx(EBX, AL)
and_(BL, 0x0f) # isolate low nybble
movzx(EDX, [:byte, ESI+EBX])
mov([EDI], DL)
dec(EDI)
# high nybble of nth byte
movzx(EBX, AL)
and_(BL, 0xf0) # isolate high nybble
struct Base {
int type;
int flags;
};
struct Frobulator {
struct Base base; /* Frobulator begins with 2 ints for type and flags */
unsigned int frob_limit;
};
require 'cstruct'
class Base < CStruct
int :type
int :flags
end
class Frobulator < Base
uint :frob_limit
end
# Appears at the beginning of every Mach object file.
class MachHeader < CStruct
uint32 :magic
int32 :cputype
int32 :cpusubtype
uint32 :filetype
uint32 :ncmds
uint32 :sizeofcmds
uint32 :flags
end
# Segment commands are one type of load command.
# Load commands all begin with the type of command it is, cmd,
# and the size of that command's struct in bytes.
class LoadCommand < CStruct
uint32 :cmd
uint32 :cmdsize
end
# Values for the cmd member of LoadCommand CStructs (incomplete).
class Section < CStruct
string :sectname, 16
string :segname, 16
uint32 :addr
uint32 :size
uint32 :offset
uint32 :align
uint32 :reloff
uint32 :nreloc
uint32 :flags
urlRegex = /\b // 1. match a word boundary, i.e. whitespace or punctuation
( // 2. capture the entire URL
( [\w-]+:\/\/? | www[.] ) // 3. protocol:// or www.
[^\s()]+ // 4. anything that's not whitespace, a paren, or an angle bracket
(?: // 5. non-capturing group (this is the last thing matched)
\([\w\d]+\) // 6. trailing parenthesized word containing only alnums (wikipedia)
| // or
( [^-!"#$%&'()*+,./:;?@[\\\]^_`{|}~\s] // 7. [^[:punct:]\s] -- anything but punctuation or whitespace
| // or
\/ // 8. a trailing slash
#!/usr/bin/env zsh
git-pull-all-branches() {
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "$pwd is not part of a git repo"
return
fi
origbranch=$(git branch | fgrep '*' | sed -e 's/\* //')
bs=($@)
[[ -z "$bs" ]] && bs=($(git branch | sed -e 's/\* //'))
var sys = require("sys"),
http = require("http"),
port = 12345,
spawn = require("child_process").spawn;
function gzipStr (str, callback) {
var child = spawn("gzip", ["-c", "-f", "-n"]),
stdout = "", stderr = "";
child.stdout.addListener("data", function (chunk) {
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;