Skip to content

Instantly share code, notes, and snippets.

View Arkham's full-sized avatar
🏠
Working from home

Ju Liu Arkham

🏠
Working from home
View GitHub Profile
[
{
"token": "nhMbMTpjMRM1zxNMQzw3g8cwiuOM9D12kQ0MDMvUGdlJ",
"mail_address": "test@example.com",
"port_not_allowed": true,
"hole": false,
"warning": true,
"info": true,
"difference": false,
"no_problem": true,
@Arkham
Arkham / poldo.rb
Created January 23, 2013 10:07
Poldo!
class Poldo
cattr_accessor :sausages
def self.all
@sausages ||= SausageFetcher.fetch!
end
def self.reload!
@sausages = SausageFetcher.fetch!
end
class AcronymSolver
attr_reader :text
def initialize(text)
@text = text
end
def self.substitutions
{
:PPC => 'Pocket PC',
@Arkham
Arkham / gist:5141232
Created March 12, 2013 08:45
mover specs
describe Wordmove::SqlMover do
context ".serialized_replace!" do
let(:content) { 'a:3:{i:0;s:20:"http://dump.com/spam";i:1;s:6:"foobar";i:2;s:22:"http://dump.com/foobar";}' }
let(:sql) { Tempfile.new('sql').tap do |d| d.write(content); d.close end }
let(:sql_path) { sql.path }
it "should replace source vhost with dest vhost" do
sql_mover.serialized_replace!('http://dump.com', 'http://shrubbery.com')
sql_mover.sql_content.should == 'a:3:{i:0;s:25:"http://shrubbery.com/spam";i:1;s:6:"foobar";i:2;s:27:"http://shrubbery.com/foobar";}'
@Arkham
Arkham / gist:5141240
Created March 12, 2013 08:47
serialized replace
def serialized_replace!(source_field, dest_field)
length_delta = source_field.length - dest_field.length
sql_content.gsub!(/s:(\d+):([\\'"]+)(.*?)\2;/) do |match|
length = $1.to_i
delimiter = $2
string = $3
string.gsub!(/#{Regexp.escape(source_field)}/) do |match|
length -= length_delta
void measureSort(const char *name, void (*sortFunction)(int *, int)) {
clock_t start,end;
double period;
int array[MAX];
initRand(array, MAX);
start = get_clock();
(*sortFunction)(array, MAX);
end = get_clock();
#include "../apue.h"
#include "sys/utsname.h"
int
main(void)
{
struct utsname *ptr;
if (uname(ptr) < 0)
err_sys("uname failed");
#include "../apue.h"
#include <time.h>
#define BUFSIZE 256
int
main(void)
{
char result[BUFSIZE];
time_t now;
@Arkham
Arkham / gist:5428923
Created April 21, 2013 08:36
POSIX compliant sleep implementation
#include "../apue.h"
static void
my_alrm(int signo)
{
/* void */
}
unsigned int
my_sleep(unsigned int nsecs)
@Arkham
Arkham / gist:5429515
Last active December 16, 2015 11:48
customer spec
require "spec_helper"
describe Customer do
subject(:customer) { Customer.new('Mario', 'Rossi') }
its(:full_name) { should == "Mario Rossi" }
context "for a single movie" do
let(:rental) { double }
before { customer.rent(rental) }