Skip to content

Instantly share code, notes, and snippets.

@elleryq
elleryq / effectlabel.py
Last active December 18, 2015 15:09
Custom QLabel Translated from C++ to Python (PySide). The origin C++ code is in http://www.serenethinking.com/2010/08/how-to-create-custom-widgets-with-qt/
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# The origin C++ code is in http://www.serenethinking.com/2010/08/how-to-create-custom-widgets-with-qt/
import sys
from PySide.QtCore import Qt
from PySide.QtGui import QLabel
from PySide.QtGui import QPen
from PySide.QtGui import QPainter
from PySide.QtCore import QPoint
@elleryq
elleryq / twitter_home_timeline.py
Created June 21, 2013 08:56
Using python_twitter to get home timeline.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from twitter import oauth_dance
from twitter import read_token_file
from twitter import OAuth
from twitter import Twitter
# You need to create application in dev.twitter.com.
@elleryq
elleryq / twitter_trends_place.py
Last active December 18, 2015 18:59
Using python_twitter to get trend.
@elleryq
elleryq / twitter_search_keyword.py
Last active December 18, 2015 19:00
Use python-twitter to search specified keyword.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""My app"""
import sys
import os
from twitter import oauth_dance
from twitter import read_token_file
from twitter import OAuth
from twitter import Twitter
@elleryq
elleryq / rvm
Created July 9, 2013 09:13
rvm for gitlab installation
#!/bin/bash
source $HOME/.rvm/scripts/rvm
rvm $@
@elleryq
elleryq / get_before_and_after_from_git_commitid.sh
Created August 6, 2013 09:46
Get before/after files from specified commit-id.
#!/bin/bash
if [ -z $1 ]; then
echo "Need commitid."
exit -1
fi
FILES=`git diff-tree --no-commit-id --name-only -r $1`
OUTPUT='/tmp/git-diff'
mkdir -p $OUTPUT
mkdir -p $OUTPUT/before
# Python functools.partial example.
from functools import partial
def foo(a, b, c, d):
return a+b+c+d
f1 = partial(foo, 1, 2)
print(f1(3, 4))
f2 = partial(foo, 1, 2, 3)
print(f2(5))
@elleryq
elleryq / fn_assign_fn.py
Created October 18, 2013 07:55
Assign function as function's method.
def foo(a, b, c):
print(a, b, c)
def get_n():
print("get_n()")
def put_n():
print("put_n()")
foo.get_n = get_n
"""http://peter-hoffmann.com/2010/extrinsic-visitor-pattern-python-inheritance.html"""
class Node(object):
pass
class A(Node):
pass
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]){
int row=0, col=0;
int i=0,j=0;
int m=0,n=0;
int tmp=0,sum=0;
float avg=0;
FILE* input=fopen("2d_ary.txt","r");