Skip to content

Instantly share code, notes, and snippets.

View masakichi's full-sized avatar
🈂️

Yuanji masakichi

🈂️
View GitHub Profile
/*
The purpose of this function is to convert an unsigned
binary number to reflected binary Gray code.
The operator >> is shift right. The operator ^ is exclusive or.
*/
unsigned int binaryToGray(unsigned int num)
{
return (num >> 1) ^ num;
}
class Solution {
public:
int singleNumber(int A[], int n) {
int x = 0;
for(int i = 0;i<n;i++){
x ^= A[i];
}
return x;
}
};
tags = db.Table('tags',
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id')),
db.Column('page_id', db.Integer, db.ForeignKey('page.id'))
)
class Page(db.Model):
id = db.Column(db.Integer, primary_key=True)
tags = db.relationship('Tag', secondary=tags,
backref=db.backref('pages', lazy='dynamic'))
@masakichi
masakichi / world_cup.py
Created June 20, 2014 02:32
World Cup in one line.
import urllib2, json
print '\n'.join([' '.join((jogo['home_team']['country'], str(jogo['home_team']['goals']), 'x', jogo['away_team']['country'], str(jogo['away_team']['goals']))) for jogo in json.loads(urllib2.urlopen('http://worldcup.sfg.io/matches').read().decode('utf-8')) if jogo['status'] == 'completed'])
#!/usr/bin/env python
#coding:utf8
import random,threading,time
from Queue import Queue
#Producer thread
class Producer(threading.Thread):
def __init__(self, t_name, queue):
threading.Thread.__init__(self,name=t_name)
self.data=queue
def run(self):
@masakichi
masakichi / all_gpa.py
Last active August 29, 2015 14:03
calculate GPA from csv file
# coding=utf8
#!/usr/bin/python
import csv
import sys
PATHS = ('/Users/Gimo/Desktop/1.csv',
'/Users/Gimo/Desktop/2.csv',
'/Users/Gimo/Desktop/3.csv',
'/Users/Gimo/Desktop/4.csv',
'/Users/Gimo/Desktop/5.csv'
@masakichi
masakichi / online_GPA.js
Created July 17, 2014 09:17
show GPA online.(designed for NJTech students)
// ==UserScript==
// @name online_GPA
// @version 0.1
// @description show GPA online.
// @include http://202.119.248.199/xscjcx_dq.aspx?xh=*
// @copyright 2014+, Gimo
// ==/UserScript==
function get_point(str){
if(str=="优秀") return 4.5;
a:link, a:visited, a:active {
color: #8e8d93;
-webkit-transition: all .15s;
-moz-transition: all .15s;
-ms-transition: all .15s;
-o-transition: all .15s;
transition: all .15s;
}
a.top:link, a.top:visited, a.top:active {
color: #000;
@masakichi
masakichi / sum_fuples_in_list
Created December 3, 2014 10:00
sum tuples in list
In [1]: l = [(1, 2), (3, 4), (5, 6), (7, 8), (9, 0)]
In [2]: [sum(x) for x in zip(*l)]
Out[2]: [25, 20]
from forwardable import def_delegators
def_delegators('event', ('begin_time', 'end_time', ))