Skip to content

Instantly share code, notes, and snippets.

View onriv's full-sized avatar
🎯
Focusing

onriv onriv

🎯
Focusing
View GitHub Profile
@onriv
onriv / readdosedata.py
Created November 14, 2013 16:15
python:test.py
#!/usr/bin/python
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import sys,getopt
#class dosedata:
@onriv
onriv / oarSimFileGen.py
Created December 3, 2013 17:10
Python:oarSimFileGen.py
#!/usr/bin/python
import os, sys, shutil, re
source_file = open(sys.argv[1])
source_name = sys.argv[1].rstrip(".egsinp")
dst_file1_name = source_name + "_colli50mm.egsinp"
dst_file2_name = source_name + "_colli40mm.egsinp"
dst_file3_name = source_name + "_colli30mm.egsinp"
dst_file4_name = source_name + "_colli25mm.egsinp"
@onriv
onriv / rules.py
Created January 8, 2014 13:30
python:textcoonvert:rules.py
class Rule:
"""
Base class for all rules.
"""
def action(self, block, handler):
handler.start(self.type)
handler.feed(block)
handler.end(self.type)
return True
@onriv
onriv / markup.py
Created January 8, 2014 13:31
python:textconvert:markup.py
import sys, re
from handlers import *
from util import *
from rules import *
class Parser:
"""
A Parser reads a text file, applying rules and controlling a
handler.
"""
@onriv
onriv / handlers.py
Created January 8, 2014 13:31
pyhton:textconvert:handlers.py
class Handler:
"""
An object that handles method calls from the Parser.
The Parser will call the start() and end() methods at the
beginning of each block, with the proper block name as a
parameter. The sub() method will be used in regular expression
substitution. When called with a name such as 'emphasis', it will
return a proper substitution function.
"""
@onriv
onriv / util.py
Last active January 2, 2016 14:29
python:textconvert:util.py
"""
handle text in an open file
lines: yield every line in the open file;
blocks: yield every block ine open file. A block is many lines containing no empty lines.
"""
def lines(file):
for line in file: yield line
# yield '\n'
@onriv
onriv / tuplesGen.py
Created March 6, 2014 17:48
python;生成所有元组;多重循环节简化;tuplesGen.py
# -*- coding: utf-8 -*-
"""
根据给定的范围,用混合进制的方式输出所有元组。
"""
def tuplesGen(ranges):
"""
>>> ranges = (2,3,4)
>>> for t in tuplesGen(ranges):
Here is a list of scopes to use in Sublime Text 2 snippets -
ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
CoffeeScript: source.coffee
@onriv
onriv / mkdir.py
Created March 16, 2014 10:54
python:mkdir:mkdir.py
# -*- coding: utf-8 -*-
def mkdir(path, relative = True):
import os
currentPath = os.getcwd().replace("\\",'/')
path = path.strip()
path = currentPath + '/' + path.replace("\\",'/').rstrip('/')
if not os.path.exists(path):
print 'The Directory ' + path + ' has been created.'
os.makedirs(path)
@onriv
onriv / OLS_20.py
Created March 21, 2014 14:26
math:KroneckerProduct
# OLS_4 = [[(0, 0), (2, 2), (3, 3), (1, 1)],
# [(2, 3), (0, 1), (1, 0), (3, 2)],
# [(3, 1), (1, 3), (0, 2), (2, 0)],
# [(1, 2), (3, 0), (2, 1), (0, 3)]]
# OLS_5 = [[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)],
# [(1, 2), (2, 3), (3, 4), (4, 0), (0, 1)],
# [(2, 4), (3, 0), (4, 1), (0, 2), (1, 3)],
# [(3, 1), (4, 2), (0, 3), (1, 4), (2, 0)],
# [(4, 3), (0, 4), (1, 0), (2, 1), (3, 2)]]