Skip to content

Instantly share code, notes, and snippets.

View rebornix's full-sized avatar
📓
Working from home

Peng Lyu rebornix

📓
Working from home
View GitHub Profile
@rebornix
rebornix / gist:3120180
Created July 16, 2012 03:06
Convert InFix String to PostFix String
private static string ConvertInFixToPostFix(string inFixExpression)
{
if (inFixExpression == null || inFixExpression.Trim().Length == 0)
return inFixExpression;
inFixExpression = inFixExpression.Replace("(", " ( ");
inFixExpression = inFixExpression.Replace(")", " ) ");
inFixExpression = inFixExpression.ToLower();
string[] tokens = inFixExpression.Split(new string[] { }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length == 0 || tokens.Length == 1)
@rebornix
rebornix / gist:3120198
Created July 16, 2012 03:08
ConvertToXml
public static XmlDocument ToXml(object thisObj)
{
XmlDocument propertyDoc = new XmlDocument();
XmlNode rootNode = propertyDoc.CreateElement(thisObj.GetType().Name.Replace("[]", "Array"));
propertyDoc.AppendChild(rootNode);
if (thisObj.GetType().IsArray)
{
Array objects = (Array)thisObj;
foreach (object obj in objects)
{
@rebornix
rebornix / gist:3174719
Created July 25, 2012 06:23
A Performance Trace Tool
using System;
using System.Diagnostics;
using System.Text;
namespace Common
{
/// <summary>
/// This class will take down the steps in the api flow, and trace it if the latency is larger than config.
/// </summary>
public static class PerfTracer
@rebornix
rebornix / gist:3227889
Created August 1, 2012 15:32
Convert between Column No & Column Name in Excel.
import sys
import string
def NameToNo(name):
result = 0
for ch in name.upper().strip("\n"):
result = result * 26 + ord(ch) - ord('A') + 1
return result
def NoToName(no):
@rebornix
rebornix / gist:3999713
Created November 2, 2012 09:24
Deploy my Dev Env
#!/bin/bash
sudo apt-get install git
git clone https://github.com/njukidreborn/vimbackup.git ~/.vim
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
ln -s ~/.vim/vimrc ~/.vimrc
ln -s ~/.vim/gvimrc ~/.gvimrc
@rebornix
rebornix / gist:4085783
Created November 16, 2012 09:17
Weibo Relation
import urllib2
import urllib
import json
import ConfigParser
COMMENTS_SHOW = 'https://api.weibo.com/2/comments/show.json'
USER_TIMELINE = 'https://api.weibo.com/2/statuses/user_timeline.json'
HDR = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
@rebornix
rebornix / rss2md.py
Created April 11, 2013 12:51
parse rss to markdown
import feedparser
rss_url = ""
feed = feedparser.parse( rss_url )
items = feed["items"]
for item in items:
time = item[ "published_parsed" ]
title = item[ "title" ].encode('gb18030')
fileName = str(time.tm_year) + '-' + str(time.tm_mon) + '-' + str(time.tm_mday) + '-' + title + '.md'
@rebornix
rebornix / CrawlerPathAPI.sh
Created January 11, 2014 13:02
Crawler4PathAPI
from bs4 import BeautifulSoup
import urllib2
url = 'https://path.com/developers/docs'
data = urllib2.urlopen(url).read()
soup = BeautifulSoup(data)
for node in soup.findAll(attrs={'class': 'curl'}):
print node.contents[0]
@rebornix
rebornix / gist:10347284
Created April 10, 2014 06:18
Create a new protocol
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\xm]
@="URL:xm Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\xm\shell]
[HKEY_CLASSES_ROOT\xm\shell\open]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MinLength
{
class Program
{