Skip to content

Instantly share code, notes, and snippets.

View kenn's full-sized avatar

Kenn Ejima kenn

View GitHub Profile
@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
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
- (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];
#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; } } \
@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};
@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.

import Foundation
class Foo : NSObject {
convenience init() {
self.init()
}
}
@kenn
kenn / doorkeeper.rb
Created June 6, 2014 16:50
Doorkeeper client_secret obfuscation
# 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)
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
# 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