Skip to content

Instantly share code, notes, and snippets.

View chew-z's full-sized avatar

Robert J. chew-z

  • Warsaw, Poland
View GitHub Profile
@chew-z
chew-z / poliposhrink.sh
Last active January 29, 2017 11:41
Script for shrinking polipo cache
#!/usr/bin/env zsh
# using GNU utils so not completely portable
# sort -h [compare human readable numbers] works only with gnu sort
# also gfind ... -delete, numfmt are GNU utils
# terminal-notifier, polipo - must be in the path
# For the reference
# gfind -mtime means that the content was modified. This date can be manually changed (e.g. with touch).
# gfind -ctime means that either the content was changed, or the file's metadata (permission, owner, etc).
# -mtime n
# evaluate as true if the file modification time subtracted
@chew-z
chew-z / bang_search.sublime-settings
Last active October 24, 2015 21:57
My settings for bang search plugin (Sublime Text)
{
"browsers_list": ["macosx","firefox", "safari"],
"definitions":
{
"!g": {
"type": "duckduckgo",
"caption": "Google Search"
},
"!gist": {
"type": "duckduckgo",
#!/usr/bin/env python
# Takes converted for privoxy (wrongly*) easylist/easyprivacy action file
# and extracts list of adresses that privoxy should block
# See https://github.com/Andrwe/privoxy-blocklist
# and my
# (*) privoxy won't interpret '\.' as regex escape in hostnames
import re
import os
host_pattern = re.compile(
@chew-z
chew-z / hosts2privoxy.py
Created September 6, 2015 22:38
Converts hosts file to privoxy action
#!/usr/bin/env python
# Takes amalgamated hosts file and converts to privoxy action file
# so you could block malicious hosts via proxy rather then /etc/hosts file
# See http://www.privoxy.org/faq/misc.html#HOSTSFILE
#
import re
import os
badguys_pattern = re.compile(
'^0.0.0.0(\s*|\t*)(.*)\n|^127.0.0.1(\s*|\t*)(.*)\n')
@chew-z
chew-z / torservice.sh
Last active September 3, 2015 13:44
Script starting/stoping/restaring tor service
#!/usr/bin/env zsh
# idea came from here:
# http://blog.felipe-alfaro.com/2015/03/05/tor-with-brew-in-mac-os-x/
# and some ideas from here:
# https://kremalicious.com/simple-tor-setup-on-mac-os-x/
# setting up Sleepwatcher best described here:
# https://www.kodiakskorner.com/log/258
function usage() {
@chew-z
chew-z / bing-wallpaper.sh
Created July 9, 2015 19:10
script downloading Bing wallpapers
#!/usr/bin/env zsh
# The mkt parameter determines which Bing market you would like to
# obtain your images from.
# Valid values are: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA.
#
# The idx parameter determines where to start from. 0 is the current day,
# 1 the previous day, etc.
#IDX=1
for IDX in 0 1 2
#coding: utf-8
#translates using Google Translate via web
import requests
import re
import clipboard
from bs4 import BeautifulSoup
def translate(phrase):
if phrase == '':
raise Exception('Nothing found in clipboard')
@chew-z
chew-z / Bitly
Last active February 15, 2016 15:06
Shorten links with Bitly API in Pythonista
#coding: utf-8
#shortens urls from clipboard using bitly
import sys
import requests
import re
import clipboard
import keychain
def shorten(long_url, token):
if re.match('\w{40,40}', token):
@chew-z
chew-z / Problem?
Last active August 29, 2015 14:16
#http://stackoverflow.com/questions/28252442/speeding-up-this-python-code-for-large-input/28261161#28261161
from bitarray import BitArray
from random import randint
import numpy as np
def SplitArray(l, r):
while(l < r):
k = randint(l, r)
arr.set_bit(k)
return SplitArray(l, k-2) + [k] + SplitArray(k+2, r)
#coding: utf-8
from operator import mul
import console
console.clear()
print 'Generating plot... (this may take a little while)'
import numpy as np
import matplotlib.pyplot as plt
GAMMA = 0.57721566490153286061