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
  • 19:47 (UTC +02:00)
View GitHub Profile
@Cediddi
Cediddi / weather_widget.py
Created September 11, 2016 14:03
A RGB weather widget written in Micropython for ESP8266. Requires urequests from micropython-lib and wemos from mplibs. Also known as Future Gadget 13-2 (Wireless WorldWideWeb Weather Widget)
from wemos import *
from machine import Pin, PWM
import machine
import time
import urequests
import urandom
red = PWM(Pin(D8), freq=512, duty=0)
green = PWM(Pin(D7), freq=512, duty=0)
blue = PWM(Pin(D6), freq=512, duty=0)
@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)
@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 / 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:]
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 / FingerPrintMiddleware.py
Last active May 1, 2020 04:42
Django Middleware for fingerprinting browsers server-side. Useful for expiring auth tokens.
"""
#Disclaimer
- Use with caution
- Don't be evil
- Respect your users
"""
class FingerPrintMiddleware(object):
def process_request(self, request):
import hashlib
@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
@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):
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
@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: