Skip to content

Instantly share code, notes, and snippets.

Frederick Cheung fcheung

Block or report user

Report or block fcheung

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fcheung
fcheung / results
Created Jul 27, 2019
unpack cookie benchmark
View results
require 'benchmark/ips'
def reverse(session_data)
digest, session_data = session_data.reverse.split('--', 2)
digest.reverse! if digest
session_data.reverse! if session_data
[session_data, digest]
end
def index(session_data)
@fcheung
fcheung / get_mem.rb
Created Jul 5, 2019
get_process_mem
View get_mem.rb
require 'ffi'
require 'get_process_mem'
require 'benchmark/ips'
module MemoryInfo
extend FFI::Library
ffi_lib 'c'
attach_function :mach_task_self, [], :__darwin_mach_port_t
attach_function :task_info,
[
@fcheung
fcheung / notes.md
Created Nov 27, 2017
changes observed from ruby mongo 1.x to 2.x
View notes.md

#Updating from mongo ruby drive 1.x to 2.x

We've recently been belatedly migrating to the 2.x series of the mongo ruby driver. At least in part this is because there's very little documentation out there on what has changed, except that there is no backwards compatibility. This post is a list of issues that we came across - I expect it is by no means exhaustive

Dependencies

Before you get started, make sure that any dependencies you have are also comaptible with mongo 2.x. For example database_cleaner needs to be 1.5 or higher

View Gemfile (initial)
source 'https://rubygems.org'
gem 'rails', '~> 4.2.7.1'
gem 'devise', '~> 3.5.0'
gem 'rspec-rails', '~> 3.4.0'
View keybase.md

Keybase proof

I hereby claim:

  • I am fcheung on github.
  • I am frederickcheung (https://keybase.io/frederickcheung) on keybase.
  • I have a public key whose fingerprint is 9A1B 5755 1E45 1BAE 41D4 8905 C4CD 3D1E B871 B631

To claim this, I am signing this object:

View tr_tree.rb
class Tree
attr_accessor :payload, :children
def initialize(payload, children = [])
@payload = payload
@children = children
end
def traverse(&block)
yield self
@children.each {|child| child.traverse(&block)}
View challenge#2.rb
class Image
attr_accessor :data
def initialize (data)
@data = data
end
def image_blur
changes = []
@data.each_with_index do |row, row_index|
View cl1.rb
class Image
attr_accessor :data
def initialize (data)
@data = data
end
def output
@data.each do |sub|
sub.each do |cell|
print cell
@fcheung
fcheung / binding.rb
Created Jun 2, 2015
binding from inside c method
View binding.rb
gem 'RubyInline'
require 'inline'
class Test
inline do |builder|
builder.include "<time.h>"
builder.c_raw <<-SRC, :arity => 1
VALUE dummy(VALUE self, VALUE arg){
VALUE ret = rb_funcall(self, rb_intern("binding"), 0);
return ret;
View bench.rb
require 'benchmark/ips'
require 'set'
set = Set[:$or, :$and, :$nor]
array = %i($or $and $nor)
Benchmark.ips do |x|
x.config(:time => 10, :warmup => 2)
You can’t perform that action at this time.