Skip to content

Instantly share code, notes, and snippets.

View jlyu's full-sized avatar

Chain Yu jlyu

View GitHub Profile
# !/bin/python
"""
The script is rewritten C as Python.
====================================================
"""
for i in range(NPATH+1):
cash_flow[i]=payoff(stock[i][tmax], pexe)
# !/bin/python
from __future__ import division
import sys
import random
"""
The script is rewritten JavaScript as Python.
====================================================
<script type="text/javascript">
<!--
@jlyu
jlyu / vimrc
Created September 5, 2012 06:03
My vim editor vimrc file. compatible with liunx and windows
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sections:
" -> General
" -> VIM user interface
" -> Colors and Fonts
" -> Files and backups
" -> Text, tab and indent related
" -> Visual mode related
" -> Moving around, tabs and buffers
" -> Status line
@jlyu
jlyu / gist:3180634
Created July 26, 2012 06:49
Python Callback
class CallbackBase:
def __init__(self):
self.__callbackMap = {}
for k in (getattr(self, x) for x in dir(self)):
if hasattr(k, "bind_to_event"):
self.__callbackMap.setdefault(k.bind_to_event, []).append(k)
elif hasattr(k, "bind_to_event_list"):
for j in k.bind_to_event_list:
self.__callbackMap.setdefault(j, []).append(k)
## staticmethod is only used to create a namespace
@jlyu
jlyu / gist:3180487
Created July 26, 2012 05:54
有关异常处理的细微区别
## 代码段A
try:
statement_A
except ...:
...
else:
statement_B
## 代码段B
@jlyu
jlyu / gist:3133191
Created July 18, 2012 00:32
python守护进程的例子
#! /usr/bin/env python2.7
#encoding:utf-8
#@description:一个python守护进程的例子
#@tags:python,daemon
import sys
import os
import time
import atexit
from signal import SIGTERM
from Queue import Queue
from threading import Thread
import time
import feedparser
num_fetch_threads = 2
enclosure_queue = Queue()
body {
padding: 0px;
margin: 0px;
font-family: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", Tahoma, "STHeiti", "Monaco";
background-color: #D6D4D2;
background-image: url("/static/img/bg.png");
min-width: 900px;
body {
padding: 0px;
margin: 0px;
font-family: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", Tahoma, "STHeiti", "Monaco";
background-color: #D6D5D2;
background-image: url("/static/img/bg.png");
min-width: 900px;
body {
padding: 0px;
margin: 0px;
font-family: "Helvetica Neue", "Luxi Sans", "DejaVu Sans", Tahoma, "STHeiti", "Monaco";
background-color: #D6D5D2;
background-image: url("/static/img/bg.png");
min-width: 900px;