This file contains hidden or 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
| Host github.com | |
| HostName github.com | |
| PreferredAuthentications publickey | |
| IdentityFile ~/.ssh/id_rsa_github | |
| Host bitbucket.org | |
| HostName bitbucket.org | |
| PreferredAuthentications publickey | |
| IdentityFile ~/.ssh/id_rsa_bitbucket |
This file contains hidden or 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
| sudo easy_install pip | |
| sudo pip install virtualenv | |
| sudo pip install virtualenvwrapper | |
| export WORKON_HOME=~/env | |
| mkdir -p $WORKON_HOME | |
| source /usr/local/bin/virtualenvwrapper.sh |
This file contains hidden or 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 add2(func): | |
| def wrapper(*args, **kwargs): | |
| return func(*args, **kwargs) + 2 | |
| return wrapper | |
| @add2 | |
| def foo(number): | |
| return number * 2 |
This file contains hidden or 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 operator import attrgetter | |
| from collections import namedtuple | |
| # Example has been given from Aaron Maxwell's The Python Next Level source | |
| class Student: | |
| def __init__(self, name, major, gpa): | |
| self.name = name | |
| self.major = major | |
| self.gpa = gpa |
This file contains hidden or 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 operator import itemgetter | |
| from functools import reduce | |
| leagues = [ | |
| { | |
| 'country': 'Switzerland', | |
| 'teams': ['Young Boys', 'Basel', 'Zürich', 'Grasshoppers', 'St. Gallen', 'Lausanne Sports', 'Thun', 'Luzerns', | |
| 'Lugano', 'Sion'] | |
| }, | |
| { |
This file contains hidden or 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
| public class Garson implements Runnable { | |
| public Kantin k; | |
| public int id, bekleme; | |
| Garson(int id, int bekleme, Kantin k) { | |
| this.id = id; | |
| this.k = k; | |
| this.bekleme = bekleme; | |
| } |
This file contains hidden or 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 quicksort(a, p, r): | |
| if p < r: | |
| q = partition(a, p, r) | |
| quicksort(a, p, q - 1) | |
| quicksort(a, q + 1, r) | |
| def partition(a, p, r): | |
| x = a[r] | |
| i = p - 1 |
This file contains hidden or 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 Lightning: | |
| lights_on = 'ON' | |
| lights_off = 'OFF' | |
| def button_action(action_type): | |
| def action_decorator(func): | |
| def action_wrapper(self): | |
| if action_type == 'on': | |
| print(self.lights_on) | |
| func(self) |
This file contains hidden or 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 addition(x): | |
| return x + 5 | |
| def subtraction(y): | |
| return y - 1 | |
| def compose(*funcs): | |
| return lambda x: reduce(lambda v, f: f(v), reversed(funcs), x) | |
| c = compose(addition, subtraction) |
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # kill all connections to the postgres server | |
| if [ -n "$1" ] ; then | |
| where="where pg_stat_activity.datname = '$1'" | |
| echo "killing all connections to database '$1'" | |
| else | |
| where="where pg_stat_activity.datname in (select datname from pg_database where datname != 'postgres')" | |
| echo "killing all connections to database" | |
| fi |
NewerOlder