Skip to content

Instantly share code, notes, and snippets.

View Cediddi's full-sized avatar
🐍
from yilan_terbiyecisi import current_user

Umut Karcı Cediddi

🐍
from yilan_terbiyecisi import current_user
  • Tacto.ai
  • München
  • 08:10 (UTC +02:00)
View GitHub Profile
@Cediddi
Cediddi / bitcoinaddressvalidator.py
Created April 15, 2014 09:34
BitCoinAddressValidator is a class that controls if the given address is valid or not. Works with plain python or django as a custom validator.
__author__ = "Umut Karci"
try:
from django.core.validators import ValidationError
from django.utils.translation import ugettext_lazy as _
except ImportError:
ValidationError = Exception
_ = lambda x: x
class BitCoinAddressValidator(object):
@Cediddi
Cediddi / isolate_signal.py
Last active August 29, 2015 14:19
Isolate signal from dispatcher. Useful for unwanted recursive save signals.
def isolate(func):
def _func(sender, instance, **kwargs):
kwargs["signal"].disconnect(_func, sender=sender)
func(sender, instance, **kwargs)
kwargs["signal"].connect(_func, sender=sender)
return _func
from requests import post
from os import listdir
for i in listdir():
with open(i, "rb") as f:
post("http://umutkarci.com/dosyayukle", files={"file":f})
@Cediddi
Cediddi / gist:5410683
Created April 18, 2013 06:48
XKCD NP-COMPLETE
#!/usr/bin/python3
import math
import itertools
APPETIZERS = {
"Mixed Fruit" : 215,
"French Fries" : 275,
"Side Salad" : 335,
"Hot Wings" : 355,
"Mozzarella Sticks" : 420,
@Cediddi
Cediddi / imapSpamTester.py
Created April 20, 2013 09:14
Spam Spam Spam!
print "Call 'instructions()' to get more info"
def instructions():
from time import sleep
instructionsdata=""" IMPORTANT!
Please be sure that you have these libs:
nltk, unidecode
Example Usage and Output:
>>> inboX = MailFactory()
>>> inboX.new_server("yourmail@gmail.com","yourpassword")
@Cediddi
Cediddi / autocomplete.py
Created April 22, 2013 06:50
A script for enabling autocomplete in OSX terminal. It also creates a function called clear() to clear screen.
import os, subprocess
pyrcfile = file(os.getenv("HOME")+"/.pythonrc","w")
pyrcfile.write("""import rlcompleter
import readline
import os
readline.parse_and_bind ("bind ^I rl_complete")
def clear():
os.system('clear')""")
pyrcfile.close()
try:
@Cediddi
Cediddi / sort_pdsh
Last active June 23, 2016 11:53
Sometimes you might want to use pdsh but you want the output to be ordered by server names. You can pipe this after the pdsh and it'll take care of the output. (shout out to @kalaomer for helping)
#!/usr/bin/env python
from sys import stdin
text = stdin.read()
from collections import defaultdict
ordered_output = defaultdict(list)
for line in text.split('\n'):
server_name = line[:line.find(':')]
server_output = line[line.find(':')+2:]
@Cediddi
Cediddi / pg_change_ownership
Created July 28, 2016 11:57
I needed a way to bulk alter ownerships to another user. This worked for me very well. Usage: ./pg_change_ownership dbname username
#!/usr/bin/env bash
dbname=$1
dbuser=$2
psql -c "alter database \"$dbname\" owner to \"$dbuser\"" $dbname;
for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" $dbname`;
do
psql -c "alter table \"$tbl\" owner to \"$dbuser\"" $dbname;
@Cediddi
Cediddi / list2tuple
Created September 9, 2016 11:59
This function takes a list and recursively changes all lists to tuples
def list2tuple(l):
"""This function takes a list and recursively changes all lists to tuples"""
rlist = []
for i in l:
if type(i) in (list, tuple, set):
rlist.append(l2t(i))
else:
rlist.append(i)
return tuple(rlist)
import turtle #ciziciyi import ediyoruz
def fraktal(uzunluk, derinlik): #yeni fonksyon
turtle.pd() #cizici cizebilsin
if derinlik == 0: #derinlik sifir ise,
turtle.forward(uzunluk) #cizici uzunluk kadar ilerlesin
else: #derinlik sifir degilse,
fraktal(uzunluk/3, derinlik-1) #fonksyon kendini cagirsin
for aci in [60,120,60]: #listedeki her deger sirayla aci olsun