Skip to content

Instantly share code, notes, and snippets.

View kenn's full-sized avatar

Kenn Ejima kenn

View GitHub Profile
@kenn
kenn / gist:51af188d35dac8069313
Last active August 29, 2015 14:01
DigitalOcean Disk Performance (May 2014)

Degradation of DigitalOcean Disk Performance

DigitalOcean's disk performance got order of magnitude worse. Compare the following test result with the ones that I did last year, when they started to support Virtio:

Probably DO started to throttle the I/O on the cheaper droplets, but the result is poor overall.

@kenn
kenn / Login.m
Last active August 29, 2015 14:01
#import "NSString+SHA1HMAC.h"
NSString *client_time = [NSString stringWithFormat:@"%f", NSDate.date.timeIntervalSince1970];
NSString *client_digest = [client_time SHA1HMACWithKey:kCliendSecret];
NSDictionary *parameters = @{@"grant_type":@"password",
@"client_id":kCliendId,
@"client_time":client_time,
@"client_digest":client_digest,
@"username":self.emailField.text,
@"password":self.passwordField.text};
#define CLASS_PROPERTY_INTERFACE(TYPE, METHOD, CMETHOD) \
+ (TYPE) METHOD; \
+ (void) set##CMETHOD:(TYPE)val; \
#define CLASS_PROPERTY_IMPLEMENTATION(TYPE, METHOD, CMETHOD) \
static TYPE _##METHOD; \
+ (TYPE) METHOD \
{ @synchronized(self) { return _##METHOD; } } \
+ (void) set##CMETHOD:(TYPE)val \
{ @synchronized(self) { _##METHOD = val; } } \
- (void)keyboardWillHideOrShow:(NSNotification *)notification
{
UIEdgeInsets tableInset = self.tableView.contentInset;
CGPoint scrollOffset = self.tableView.contentOffset;
UIToolbar *toolbar = self.navigationController.toolbar;
CGRect toolbarFrame = toolbar.frame;
NSDictionary *userInfo = notification.userInfo;
NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationCurve curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
require 'openssl'
module Crypto
module_function
def encrypt(iv, data)
enc = OpenSSL::Cipher::AES256.new(:CBC)
enc.encrypt
enc.key = key_with_padding(iv)
(enc.update(data) + enc.final).unpack("H*").first
@kenn
kenn / gist:9126899
Last active August 29, 2015 13:56
SSH key deploy by Capistrano
task :ssh do
require 'open-uri'
require 'sshkey'
keys = ['kenn', 'dhh'].map do |name|
open("https://github.com/#{name}.keys").read
end.join("\n") << "\n"
abort "Invalid keys:\n#{keys}" unless keys.split("\n").all?{|i| SSHKey.valid_ssh_public_key?(i) }
put keys, '/home/deploy/.ssh/authorized_keys', mode: 0600
end
@kenn
kenn / gist:7071032
Last active December 26, 2015 01:28
SELECT * FROM
(SELECT id FROM sort_keys ORDER BY sort_key) INNER JOIN main_table ON sort_keys.id = main_table.id
WHERE ... OFFSET 0 LIMIT 10
@kenn
kenn / gist:7061067
Last active December 25, 2015 23:59
Validating MinHash's errors
require 'digest'
a = (0..100000).map{|i| Digest::SHA1.hexdigest(i.to_s).hex }
a.map.with_index{|i,idx| i > a[idx-1] }.group_by{|i| i }.map{|k,v| [k,v.size] }
# => [[true, 499235], [false, 500766]]
# Undo require 'active_support/core_ext/object/to_json'
require 'yajl'
[Object, Array, Hash].each do |klass|
klass.class_eval <<-RUBY, __FILE__, __LINE__
def jsonize(options = nil)
::Yajl::Encoder.encode(self)
end
RUBY
end
E, [2013-04-22T15:04:52.652797 #8734] ERROR -- : listen loop error: closed stream (IOError)
E, [2013-04-22T15:04:52.652852 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:652:in `select'
E, [2013-04-22T15:04:52.652886 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:652:in `worker_loop'
E, [2013-04-22T15:04:52.652918 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/newrelic_rpm-3.6.0.83/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `call'
E, [2013-04-22T15:04:52.652950 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/newrelic_rpm-3.6.0.83/lib/new_relic/agent/instrumentation/unicorn_instrumentation.rb:22:in `block (4 levels) in <top (required)>'
E, [2013-04-22T15:04:52.652981 #8734] ERROR -- : /usr/local/rvm/gems/ruby-2.0.0-p0/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
E, [2013-04-22T15:04:52.653013 #8734] ERROR -- : /usr/local/rvm/gems/ruby