Skip to content

Instantly share code, notes, and snippets.

def replace(path, pattern, replacement)
File.open(path, "r+") do |file|
contents = file.read
file.truncate(0)
file.pos = 0
file << contents.gsub(pattern, replacement)
end
end
@samuelkadolph
samuelkadolph / gitchart.rb
Last active December 14, 2015 22:28
Creates a neat little chart for your git log based on keywords you provide.
#!/usr/bin/env ruby
require "date"
require "digest/md5"
require "erb"
require "optparse"
require "ostruct"
require "shellwords"
require "tempfile"
#include <pthread.h>
#include <stdio.h>
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
extern void __wait() {
printf("__wait pthread_mutex_lock # => %d\n", pthread_mutex_lock(&mutex));
printf("__wait pthread_cond_wait # => %d\n", pthread_cond_wait(&cond, &mutex));
printf("__wait pthread_mutex_unlock # => %d\n", pthread_mutex_unlock(&mutex));
$ sudo lsof -p 26564
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 26564 root cwd DIR 202,1 4096 524302 APP_PATH/releases/20120726200801
ruby 26564 root rtd DIR 202,1 4096 2 /
ruby 26564 root txt REG 202,1 7265143 279257 /usr/lib/ruby/1.9.3-p194/bin/ruby
ruby 26564 root mem REG 202,1 101192 20884 /lib/x86_64-linux-gnu/libresolv-2.13.so
ruby 26564 root mem REG 202,1 31120 20306 /lib/x86_64-linux-gnu/libnss_dns-2.13.so
ruby 26564 root mem REG 202,1 88384 3968 /lib/x86_64-linux-gnu/libgcc_s.so.1
ruby 26564 root mem REG 202,1 5920 278994 /usr/lib/ruby/1.9.3-p194/lib/ruby/1.9.1/x86_64-linux/fiber.so
ruby 26564 root mem REG 202,1 6120 279010 /usr/lib/ruby/1.9.3-p194/lib/ruby/1.9.1/x86_64-linux/digest/md5.so
D, [2012-07-19T03:46:53.479610 #22645] DEBUG -- : waiting 4.0s after suspend/hibernation
I, [2012-07-19T03:46:48.494536 #28377] INFO -- : Rainbows! ThreadPool worker_connections=100
E, [2012-07-19T03:46:47.459752 #22645] ERROR -- : reaped #<Process::Status: pid 22656 SIGKILL (signal 9)> worker=0
E, [2012-07-19T03:46:47.439877 #22645] ERROR -- : worker=0 PID:22656 timeout (7s > 6s), killing
D, [2012-07-19T03:45:11.205523 #14678] DEBUG -- : waiting 4.0s after suspend/hibernation
I, [2012-07-19T03:45:06.220187 #20041] INFO -- : Rainbows! ThreadPool worker_connections=100
E, [2012-07-19T03:45:05.185902 #14678] ERROR -- : reaped #<Process::Status: pid 14689 SIGKILL (signal 9)> worker=0
E, [2012-07-19T03:45:05.167189 #14678] ERROR -- : worker=0 PID:14689 timeout (7s > 6s), killing
D, [2012-07-19T03:42:08.010851 #30981] DEBUG -- : waiting 4.0s after suspend/hibernation
I, [2012-07-19T03:42:03.025937 #3666] INFO -- : Rainbows! ThreadPool worker_connections=100
* json (1.7.3)
* kgio (2.7.4)
* linecache19 (0.5.12)
* mongrel (1.2.0.pre2)
* mysql2 (0.2.6)
* nokogiri (1.5.5)
* raindrops (0.10.0)
* unicorn (4.3.1)
@samuelkadolph
samuelkadolph / unicode_parser.rb
Created September 7, 2011 17:45
Turn "\\u2603" to "☃" in ruby without eval
class String
def parse_unicode
dup.parse_unicode!
end
def parse_unicode!
gsub!(/\\u([0-9a-fA-F]{4})/) { [$1.to_i(16)].pack("U") }
end
end
method(:foo).to_java.source_location(Thread.current.to_java.getContext())
require "ffi"
class ULLEnum < FFI::Enum
def native_type
FFI::Type::ULONG_LONG
end
end
class MachMsgHeader < FFI::Struct
layout :bits, :uint, :size, :uint, :remote_port, :uint, :local_port, :uint, :reserved, :uint, :id, :int
@samuelkadolph
samuelkadolph / getpass.rb
Created August 10, 2011 19:44
Use getpass using FFI for ruby
require "ffi"
module GetPass
extend FFI::Library
ffi_lib "libc"
attach_function :getpass, [:string], :string
end
GetPass.getpass("Prompt: ") # => "secret"