Skip to content

Instantly share code, notes, and snippets.

View lithuak's full-sized avatar

Ilya Persky lithuak

  • Ukraine
View GitHub Profile
@lithuak
lithuak / lj_spider.py
Last active January 6, 2018 21:20
Export cookies from Chrome db to Scrapy format
import sqlite3
def get_chrome_cookies():
conn = sqlite3.connect('/home/<username>/.config/chromium/Default/Cookies')
query = 'select name, value, path from cookies where host_key=".livejournal.com";'
return [{"name": r[0], "value": r[1], "path": r[2]} for r in conn.execute(query)]
@lithuak
lithuak / gist:7294386
Created November 3, 2013 20:24
clear chrome internal DNS by this URL:
chrome://net-internals/#dns
@lithuak
lithuak / gist:7606081
Created November 22, 2013 20:13
Fix WiFi on Ubuntu/Dell
http://askubuntu.com/questions/346804/one-ubuntu-laptop-on-wifi-occasionally-makes-other-laptops-connection-slow
sudo sh -c "echo 'blacklist wl' >> /etc/modprobe.d/broadcomm-blacklist.conf"
sudo sh -c "echo 'brcmsmac' >> /etc/modprobe.d/broadcomm.conf"
"
When I do this, I end up with no kernel driver in use and no wifi.
Actually, it looks like brcmsmac was already blacklisted in a different modprobe.d/ file, created by bcmwl. I commented that out and rebooted and brcmsmac was active.
@lithuak
lithuak / exper.py
Created February 28, 2014 11:28
Saving/restoring local aware time as naive utc to/from DB
# timezones
tz_utc = pytz.utc
tz_ua = pytz.timezone('Europe/Kiev')
# get aware ukraine time
time_ua = datetime.now(tz_ua)
print "Aware ukraine time:", time_ua
# transform to utc
time_utc = time_ua.astimezone(tz_utc)
print "Aware utc time:", time_utc
# make naive
@lithuak
lithuak / whoes waves are years
Created February 28, 2014 11:56
util functions to translate between aware and naive times with tz change
from datetime import datetime
import pytz
tz_utc = pytz.utc
tz_ua = pytz.timezone('Europe/Kiev')
def aware_time_to_naive(t):
return t.replace(tzinfo=None)
@lithuak
lithuak / gist:9430024
Created March 8, 2014 12:44
Windows 7 logon/logoff scripts
First of all launch the Group Policy Editor by clicking Start, then type gpedit.msc and hit Enter.
Now navigate to the User Configuration > Windows Settings > Scripts(Log on/Log off) option.
@lithuak
lithuak / gist:9932115
Created April 2, 2014 11:11
Python/MySQL on Windows
1. MySQL community edition (installer, 32bit) will install python connector
2. No additional packages are needed
3. Connection url would be like this: mysql+mysqlconnector://root:root@localhost/my_db_name
@lithuak
lithuak / gist:9989051
Created April 5, 2014 08:32
fabric on windows
1. binary dependencies from here:
http://blog.victorjabur.com/2011/06/08/modules-python-library-compiled-for-windows-32-and-64-unofficial-windows-binaries-for-python/
a) pycrypto-2.3.win32-py2.7.exe
b) paramiko-1.7.7.1.win32-py2.7.exe
2. just pip install fabric
3. Add C:\Python27\Scritps to PATH
@lithuak
lithuak / gist:10458847
Created April 11, 2014 11:06
Make matplotlib plot two times bigger
import matplotlib
matplotlib.rcParams['savefig.dpi'] = 2 * matplotlib.rcParams['savefig.dpi']
http://nbviewer.ipython.org/gist/minrk/3301035
http://calebmadrigal.com/big-graphs-ipython-notebook/
@lithuak
lithuak / gist:ac77e567f3343e315835
Created June 16, 2014 12:43
Set WM keybinding for Gnome
for i in $(seq 1 8); do gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-$i "['<Control>F$i']"; done
What happens here:
Settings are stored in dconf (see man 7 dconf) and can be visually accessed by dconf-editor (not installed by default) or gsettings (recommended API for command line). Next steps are clear.