Skip to content

Instantly share code, notes, and snippets.

View harunyasar's full-sized avatar

Harun Yasar harunyasar

  • Hyperware LTD
  • Oxford
  • 10:11 (UTC +01:00)
View GitHub Profile
@harunyasar
harunyasar / save_pdf.py
Created January 18, 2016 11:59
Python open file binary mode
import base64
file_data = base64.urlsafe_b64decode(pdf.encode('utf8'))
with open('pdf_name.pdf', 'wb') as file:
file.write(file_data)
return pdf
@harunyasar
harunyasar / the_diamond_problem.py
Last active April 26, 2016 08:13
The Diamond Problem
class class_a(object):
def speak(self):
print("class_a sinifindan cagirildi")
class class_b(class_a, object):
def speak(self):
print("class_b sinifindan cagirildi")
super(class_b, self).speak()
class class_c(class_a, object):
@harunyasar
harunyasar / callable_object.py
Created May 2, 2016 17:25
Callable object in Python
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __call__(self, x, y):
self.x = x
self.y = y
point = Point(5, 1)
@harunyasar
harunyasar / brew_psql.sh
Created December 7, 2016 06:20
Postgresql with Brew
brew install postgresql
brew tap homebrew/services
brew services start postgresql
brew services list
@harunyasar
harunyasar / enable_ff.sh
Created January 4, 2017 14:07
Enable fast forward in git-flow-avh
git config gitflow.feature.finish.no-ff true
@harunyasar
harunyasar / kill.sh
Created February 23, 2017 08:29
Kill all PostgreSQL connections
#!/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
@harunyasar
harunyasar / function_composition.py
Created March 10, 2017 12:07
Example of function composition with Python
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)
@harunyasar
harunyasar / function_decorator_in_a_class.py
Created March 20, 2017 11:53
How to use Python function decorators in a class?
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)
@harunyasar
harunyasar / quicksort.py
Created April 26, 2017 06:06
Quicksort with Python
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
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;
}