Skip to content

Instantly share code, notes, and snippets.

@benolee
benolee / archive.sh
Created September 28, 2017 07:13 — forked from marshallm/archive.sh
Baseline pt-archiver bash script for MySQL
#!/bin/bash
source mysql_access
TODAY=$(date +"%Y-%m-%d_%H%M%S")
CHECK_RETAINER=$(
mysql api_test \
-u$MYSQL_USER \
-p$MYSQL_PASS \
-h$SOURCE_HOST \
--socket=$MYSQL_SOCK \

Debugging ruby performance - Aman Gupta

C, Linux, networks, cpu, and memory usage

  • lsof -nPp <pid>
  • tcpdump
  • write the data to a file, load it up in wireshark
  • strace, trace systems calls and signals (jump into kernelspace)
  • SIGVTALRM, ruby 1.8 every 10msec to switch threads (green threads)
  • posix-spawn instead of fork-exec, check out posix-spawn gem
  • ltrace

– ltrace -c ruby foo.rb # summary mode

@benolee
benolee / curl.md
Last active August 29, 2015 14:06 — forked from btoone/curl.md

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
$ env | grep LC
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
$ env | grep LANG
LANG=en_US.UTF-8
$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
require 'rack'
class StackFrame
def initialize app
@app = app
end
def call env
p [:call, self.to_s, env]
_env = env.reduce(:merge)
def f a, b = Proc.new
Module.new {
const_set :M__, self
module_exec self, *a, &b
}
end
m1 = module f(:m1_ok) { |mod, sym| @foo = sym }::M__
def foo
@foo
def enum blk = Proc.new
m = Module.new
o = Object.new
o.instance_eval {
@enum_idx = -1
@enum_mod = m
def method_missing(n, *a)
n =~ /([A-Z][A-Z_]*)(=)?/
raise "bad enum name #{n}" unless $1
if $2
@benolee
benolee / Wat.hs
Last active August 29, 2015 14:04
-- Exercise 1
-- converts positive Integers to a list of digits.
toDigits :: Integer -> [Integer]
toDigits x = reverse (toDigitsRev x)
toDigitsRev :: Integer -> [Integer]
toDigitsRev x
| x <= 0 = []
| otherwise = (mod x 10) : toDigitsRev (div x 10)
I = -> x { x }
C = -> x { -> y { -> z { x[z][y] } } }
T = -> C[I]
K = -> x { -> y { x } }
U = -> f { f[f] }
# I know, this technically isn't the Y combinator,
# and it isn't exactly the Z combinator either (like Y, but for applicative order languages).
Y = -> g { U[-> f { -> x { g[U[f]][x] } } ] }
puts "toplevel Module nesting: #{Module.nesting.inspect}"
class Foo
def bar
puts "hello from Foo#bar"
end
end
::ExportedFoo = Foo