Skip to content

Instantly share code, notes, and snippets.

View gornostal's full-sized avatar

Oleksandr Gornostal gornostal

  • Kyiv, UA
View GitHub Profile
@gornostal
gornostal / duplicate_line.py
Created July 1, 2012 12:34
Sublime plugin for duplicating lines
import sublime, sublime_plugin
class DuplicateLineCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
line = self.view.line(region)
line_contents = self.view.substr(line) + '\n'
self.view.insert(edit, line.begin(), line_contents)
@gornostal
gornostal / cleanup.py
Created August 21, 2012 15:46
cleanup.py
#!/usr/bin/env python
import glob
import os
import sys
if len(sys.argv) < 2:
print "Usage: ./cleanup.py path/to/dir/ [max_dir_size_in_gb]"
sys.exit()
@gornostal
gornostal / .bashrc
Created September 18, 2012 14:26
.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
@gornostal
gornostal / audible.js
Last active December 23, 2015 02:59
Scrape audible search results
/**
* To run use http://nrabinowitz.github.com/pjscrape/
* 1. $ phantomjs pjscrape.js audible.js
* 2. Register on mongolab.com
* 3. $ mongoimport -h ds0466148.mongolab.com:45598 -d <dbname> -c <collection> -u <user> -p <password> --file audible.json --jsonArray
* 4. Install greasemonkey (Firefox) or tempermonkey (Chrome)
* 5. Add this userscript https://gist.github.com/gornostal/6570526
* 6. Open https://mongolab.com/databases/audible/collections/fiction_books or whatever you have
*/
@gornostal
gornostal / audible-mongolab.js
Created September 15, 2013 12:53
Tampermonkey script for audible collections in mongolab
// ==UserScript==
// @name Audible-Mongolab
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description https://gist.github.com/gornostal/6570516
// @match https://mongolab.com/databases/audible/collections/*
// @copyright 2012+, You
// ==/UserScript==
@gornostal
gornostal / README.md
Last active June 7, 2019 16:20
Install Hackintosh OS X Yosemite on Sony Vaio VPC-F11M1R/H

Successfully installed OS X Yosemite on my Sony VAIO F11M1R/H.

Problems:

  • I had to buy USB sound card for $10 (Viewcon VE533 works for me), because I couldn't find audio drivers.
  • OS X won't connect to password protected Wi-Fi networks, so I had to remove a password.

So here's the steps that I followed:

  1. Make a bootable flash drive using UniBeast tool
@gornostal
gornostal / conftest.py
Created March 6, 2015 11:59
conftest.py
import pytest
class DictHasValus(dict):
"""
DictHasValus({('foo', 'bar'): 'hello'}) == {'foo': {'bar': 'hello'}}
"""
def __eq__(self, other):
try:
@gornostal
gornostal / .tmux.conf
Created October 6, 2015 15:34
.tmux.conf
# tmux v2.0 installation steps for Ubuntu 14.04 (Trusty Tahr)
# tmux -V
# sudo apt-get update
# sudo apt-get install -y python-software-properties software-properties-common
# sudo add-apt-repository -y ppa:pi-rho/dev
# sudo apt-get update
# sudo apt-get install -y tmux
# tmux -V
# use UTF8
@gornostal
gornostal / spuploader.sh
Last active October 30, 2015 10:33
Upload files via serial port to a device
#!/bin/bash
target="$1"
remotePath="$2"
device="${3:-/dev/ttyUSB0}"
# compress target files using tar | encode data to base64 string | remove \n
compress="tar -C `dirname $target` -cjvf - `basename $target` | base64 | tr -d '\n'"
# decode base64 string using python (using python because my device doesn't have base64)
base64decode="import base64, sys; sys.stdout.write(base64.b64decode(sys.stdin.read()))"
@gornostal
gornostal / Unicode.md
Created November 22, 2015 10:15
Python 2.7. Unicode Errors Simply Explained

Python 2.7. Unicode Errors Simply Explained

I know I'm late with this article for about 5 years or so, but people are still using Python 2.x, so this subject is relevant I think.

Some facts first:

  • Unicode is an international encoding standard for use with different languages and scripts
  • In python-2.x, there are two types that deal with text.
    1. str is an 8-bit string.
  1. unicode is for strings of unicode code points.