Skip to content

Instantly share code, notes, and snippets.

Avatar

Kenn Ejima kenn

  • San Francisco
View GitHub Profile
@kenn
kenn / gist:9126899
Last active Aug 29, 2015
SSH key deploy by Capistrano
View gist:9126899
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
View crypto.rb
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
View MessagesViewController.m
- (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];
View BlackMagic.h
#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; } } \
View Login.m
#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};
@kenn
kenn / gist:51af188d35dac8069313
Last active Aug 29, 2015
DigitalOcean Disk Performance (May 2014)
View gist:51af188d35dac8069313

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.

View gist:b122e4ee58c513cbc7a3
import Foundation
class Foo : NSObject {
convenience init() {
self.init()
}
}
@kenn
kenn / doorkeeper.rb
Created Jun 6, 2014
Doorkeeper client_secret obfuscation
View doorkeeper.rb
# config/initializers/doorkeeper.rb
Doorkeeper.configure do
client_credentials :from_obfuscated_params
end
module Doorkeeper
module OAuth
class Client
module Methods
def from_obfuscated_params(request)
View gist:c59256c77af5fc03b241
mysql> explain SELECT * FROM messages USE INDEX (index_messages_on_friend_id_and_id) WHERE friend_id = 100 AND (id < 1000000) ORDER BY id DESC LIMIT 10\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: messages
type: range
possible_keys: index_messages_on_friend_id_and_id
key: index_messages_on_friend_id_and_id
key_len: 8
ref: NULL
View gist:fd4cc798804508c3de6d
# cat auth.log | grep Failed | grep root | cut -d ' ' -f 11 | sort | uniq
111.74.238.101
111.74.238.103
111.74.238.104
111.74.238.124
111.74.238.138
111.74.238.151
111.74.238.152
111.74.238.153
111.74.238.167