This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from subprocess import Popen, PIPE | |
from os import path | |
git_command = ['/usr/bin/git', 'status'] | |
repository = path.dirname('/path/to/dir/') | |
git_query = Popen(git_command, cwd=repository, stdout=PIPE, stderr=PIPE) | |
(git_status, error) = git_query.communicate() | |
if git_query.poll() == 0: | |
# Do stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save one object's type and use as a function later | |
type_1 = type(type_1_obj) | |
type_2_to_1 = type_1(type_2_obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby/C/Fortran Bridge Rakefile | |
# Cameron Carroll, July 2012 | |
# Purpose: Rake build script to facilitate calling Fortran code from Ruby in order to outsource | |
# heavy lifting computation. This script will compile Fortran and C code in present directory | |
# but leaves implementation and linking up to the user. | |
# | |
# Notes: This script may require a little bit of configuration depending on the system. | |
# 1: The Ruby include flags are specifically for MY system. I haven't found a way to generate them, | |
# so you have to either tailor them by hand or generate a extconf.rb makefile, enable verbose mode, | |
# and copy the include flags from the compile command. Yeah, I know, I know... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- the following variable allows to choose what we want to export | |
-- it can be "Selected Papers Only", "Selected Collection" or "Entire Library" | |
set myDesiredSaveRange to "Selected Collection" | |
-- the following variable allows is the path where we save the bib file | |
set myPath to "~/Desktop/from_papers.bib" | |
-- do we also have a prettifier? | |
set runPrettifier to true | |
-- path to it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults write com.apple.dock wvous-show-windows-in-other-spaces -bool FALSE | |
killall Dock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Compact_assignment_from_pparams(object): | |
def __init__(self, p1, p2, p3, p4, p5, p6): | |
for key, value in locals().items(): | |
setattr(self, key, value) | |
class Compact_assignment_from_kwargs(object): | |
def __init__(self, **kwargs): | |
for key, value in kwargs.items(): | |
setattr(self, key, value) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Select python version | |
port select --list python | |
port select --set python python33 | |
# Select cython version | |
port select --list cython | |
port select --set cython cython33 | |
# Select ipython version | |
port select --list ipython |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_docstring(*args): # decorator factory function | |
""" | |
Constructs and appends a docstring to the decorated function's existing docstring. | |
When several functions share the same docstring(s), can be used to improve code readability. | |
Also makes life easier should the documentation ever need to be updated. | |
To understand decorators: simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ | |
'join' a list of strings ('+' building is quadratic time): memonic.com/user/pneff/folder/python/id/1bufp | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using std::cout, std::endl; | |
int x = 0; | |
int pre = ++x; // ++x incremements x, and returns (the incremented value of) x | |
cout << pre << ', ' << x << endl; // 1, 1 | |
int post = x++; // x++ returns (the original value of) x, and incremements x | |
cout << post << ', ' << x << endl; // 1, 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = dict(state='active', canonical_name='un#ep') | |
print('Endpoint %(canonical_name)s is %(state)s' % data) | |
print('Endpoint {canonical_name} is {state}'.format(**data)) | |
foo, bar = 'foo', 'bar' | |
print('%(foo)s%(bar)s' % locals()) | |
print('{foo}{bar}'.format(**locals())) | |
print('{foo}{bar}'.format(foo='foo', bar='bar')) # how much faster is % formatting? | |
# TODO: is nesting possible? |
OlderNewer