Skip to content

Instantly share code, notes, and snippets.

View cizixs's full-sized avatar
:octocat:
cloud native coding...

cizixs cizixs

:octocat:
cloud native coding...
View GitHub Profile

Add the following chunk to your existing ISC dhcpd.conf file.

if exists user-class and ( option user-class = "iPXE" ) {
    filename "http://boot.smidsrod.lan/bootstrap.ipxe";
}
else {
    filename "undionly.kpxe";
}

(or see https://gist.github.com/4008017 for a more elaborate setup

@cizixs
cizixs / translator.py
Last active December 20, 2015 16:49
Python translate method wrapper, from Python Cookbook
import string
def translator(frm='', to='', delete='', keep=None):
if len(to) == 1:
to = to * len(frm)
trans = string.maketrans(frm, to)
if keep is not None:
allchars = string.maketrans('', '')
delete = allchars.translate(allchars, keep.translate(allchars,delete))
def translate(s):
@cizixs
cizixs / process_word.py
Last active December 20, 2015 19:28
create a iterator to process every word in a file. from Python Cookbook!
def words_of_file(thefilepath, line_to_words=str.split)
the_file = open(thefilepath)
for line in the_file:
for word in line_to_words(line):
yield word
the_file.close()
for world in worlds_of_file(thefilepath):
dosomethingwith(word)
@cizixs
cizixs / cout.py
Last active June 12, 2020 21:45
Using c++ stream operator << in python. This gist is from python cookbook.
class IOManipulator(object):
def __init__(self, function=None):
self.function = function
def do(self, output):
self.function(output)
def do_endl(stream):
stream.output.write('\n')
stream.output.flush()
@cizixs
cizixs / reverseArray.py
Created August 12, 2013 15:17
reverse a two-dimension array in python
arr = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
print [[r[col] for r in arr] for col in rage(len(arr[0]))]
#another simple but confuding way
print map(list, zip(*arr))
@cizixs
cizixs / addItem.py
Created August 12, 2013 15:29
This gist lists some pythonic dict manipulation from Python Cookbook.
def addItem(theIndex, word, pagenumber):
theIndex.setdefault(word, [ ]).append(pagenumber)
#the above method equals to the following
def addItem(theIndex, word, pagenumber):
if word in theIndex:
theIndex[word].append(pagenumber)
else:
theIndex[word] = [pagenumber]
#!/usr/bin/env python
# Describe classes, methods and functions in a module.
# Works with user-defined modules, all Python library
# modules, including built-in modules.
import inspect
import os, sys
INDENT=0
_foo()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --verbose --version"
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
First, clone a remote Git repository and cd into it:
$ git clone git://example.com/myproject
$ cd myproject
Next, look at the local branches in your repository:
$ git branch
* master
But there are other branches hiding in your repository! You can see these using the -a flag:
$ git branch -a