Skip to content

Instantly share code, notes, and snippets.

View arya's full-sized avatar

Arya Asemanfar arya

  • San Francisco, California
View GitHub Profile
@arya
arya / git-godeps
Last active January 17, 2018 22:58
#!/bin/bash
set -o errexit -o nounset -o pipefail
package=$1
package_dir=$(go list -f '{{.Dir}}' ${package})
pushd ${package_dir} > /dev/null
git_root=$(git rev-parse --show-toplevel)
pushd ${git_root} > /dev/null
package main
import (
"fmt"
"os/exec"
"syscall"
"time"
)
func main() {
@arya
arya / gist:4159460
Created November 28, 2012 06:42
gc.log
{Heap before time travel invocations=2863 (full 0):
par new generation total 26424128K, used 23502462K [0x00007f5be2710000, 0x00007f62e2710000, 0x00007f62e2710000)
eden space 23488128K, 100% used [0x00007f5be2710000, 0x00007f617c0b0000, 0x00007f617c0b0000)
from space 2936000K, 0% used [0x00007f622f3e0000, 0x00007f62301dfbc8, 0x00007f62e2710000)
to space 2936000K, 0% used [0x00007f617c0b0000, 0x00007f617c0b0000, 0x00007f622f3e0000)
concurrent mark-sweep generation total 4070400K, used 1401580K [0x00007f62e2710000, 0x00007f63dae10000, 0x00007f63daf10000)
concurrent-mark-sweep perm gen total 122880K, used 56338K [0x00007f63daf10000, 0x00007f63e2710000, 0x00007f63e2710000)
2012-11-28T06:39:17.165+0000: 50432.440: [GC 50432.440: [ParNew
Desired survivor size 1503232000 bytes, new threshold 6 (max 6)
- age 1: 62804920 bytes, 62804920 total
scala> class Foo extends scala.collection.mutable.Queue[Int] {
|
| def foo = last0
| }
defined class Foo
scala> new Foo
res0: Foo = ()
scala> res0.enqueue(1)
class Module
UNITS = %w{second minute hour day week month year solar_year}.map { |s| s.upcase }
CONVERSIONS = [1, 60, 60, 24, 7, 30 / 7.0, 365 / 30.0, 31558150 / 31536000.0]
def const_missing(name)
if name.to_s =~ /^T_([0-9]+)_(#{UNITS.join("|")})S?$/
num = $1.to_i
unit = $2
previous_unit_index = UNITS.index(unit) - 1
value = if previous_unit_index < 0
num
class MemcacheLock
class LockTimeout < StandardError; end
LOCK_VALUE = "#{Process.pid}#{Time.now.usec}".to_i # not really important right now
LOCK_TTL = 40
KEEP_DURATIONS = 100
EXPIRE_DURATION_ESTIMATE = 60
MAX_RETRIES = 20
MAX_RETRY_DELAY = 0.7
def initialize(memcache, default_duration = nil)
class MergeColumn
def initialize(array)
@array = array
@index = 0
end
def value
@array[@index]
end
int
rb_str_hash(str)
VALUE str;
{
register long len = RSTRING(str)->len;
register char *p = RSTRING(str)->ptr;
register int key = 0;
#if defined(HASH_ELFHASH)
register unsigned int g;
module Bluepill
module ProcessConditions
class ProcMemUsage < MemUsage
def run(pid)
begin
total = 0
File.read("/proc/#{pid}/smaps").split("\n").each do |line|
line =~ /^(Private)_Dirty: +(\d+)/
if $2
total += $2.to_i
module User::Extras
# ActiveRecord, at the time of this writing, always writes serialized attributes to the database, even if it hasn't changed.
# See http://github.com/rails/rails/commit/992fda16ed662f028700d63a8dcbd1837f1d58ab for the patch that introduced this.
# So to get around it, we're going to handle the serialization of the extras hash ourselves.
def self.included(klass)
klass.class_eval do
before_save :serialize_extras_attribute
end
klass.extend(ClassMethods)