Skip to content

Instantly share code, notes, and snippets.

View yao2030's full-sized avatar

yao2030 yao2030

  • Shanghai, China
View GitHub Profile
#pragma mark - NSCoding
- (id)initWithCoder:(NSCoder *)decoder {
self = [super init];
if (!self) {
return self;
}
unsigned int count;
objc_property_t *properties = class_copyPropertyList([self class], &count);
for (NSUInteger i = 0; i < count; i++) {
void to_binary(unsigned long n)
{
int r;
r = n % 2;
if (n >= 2)
to_binary(n / 2);
putchar('0' + r);
}
/*
Licensed under the MIT License
Copyright (c) 2011 Cédric Luthi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
# -*- coding: UTF-8 -*-
import os
import sys
from Queue import Queue
import random
import threading
import time
@yao2030
yao2030 / Barbecue.py
Last active December 30, 2015 08:49
test
import time
import random
class Customer:
def __init__(self, id):
self.id = id
self.foods = []
self.start = time.time()
def choose_foods(self):
self.foods = random_choose(5)
@yao2030
yao2030 / sema.py
Created December 5, 2013 12:16
python multithreading semaphore
#!/usr/bin/env python
import threading
import urllib2
import time, random
class GrabUrl(threading.Thread):
def __init__(self, arg0):
threading.Thread.__init__(self)
self.host = arg0
#!/usr/local/bin/python2.7
x = [
{ "a": "hoooooo",
"b": "wo",
"c": "rrrruuu",
},
{
"a": "en?",
"b": "wwwwlllllyyy",
#!/usr/local/bin/python2.7
grad = {}
stu = {}
with open("input.txt") as f:
for l in f:
name, score = l.strip().split()
if name not in grad:
grad[name] = 0
@yao2030
yao2030 / conf_ini.py
Created November 1, 2013 13:45
read a configuration file
#!/usr/local/bin/python2.7
section = ""
ini_dict = {}
with open("input.txt") as f:
for l in f:
x = l.strip()
if not x:
@yao2030
yao2030 / ex02.sh
Created September 26, 2013 09:17
ex02.sh(new)
#!/usr/bin/sh
pipe=/tmp/out
#trap "rm -rf $pipe" EXIT
#if [[ ! -p $pipe ]]; then
# mkfifo $pipe
#fi
out=1
while true
do