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 / 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 / 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')
#!/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 / 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",
@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 / connected.sh
Last active December 1, 2015 05:09
connected.sh
#!/bin/bash
# It is complicated - not my fault. It's Apple implementing changes in launchctl on 10.10, 10.11
# This script restarts Polipo service (as user not root) after connectiong to VPN via Tunnelblick
# The reason for this restart is that when on Public WiFi connections are blocked by LittleSnitch (firewall)
# Polipo goes crazy waiting for all these connections that disappeared in a black hole
# 'Couldn't establish listening socket: Too many open files'
# So it is better to start clean after getting VPN connection and I am too lazy to do that from commandline.
# Some explanations of why all this is necessary
# http://apple.stackexchange.com/questions/195445/
@chew-z
chew-z / hostsblock.sh
Created December 7, 2015 08:56
Blocking evil servers via dnsmasq
#!/usr/bin/env zsh
# MODIFY SETTINGS VIA THE CONFIGURATION FILES IN
# conf/
# eval PATH=/opt/usr/sbin:/opt/etc/init.d:$PATH
# CHECK FOR NEEDED AND OPTIONAL UTILITIES AND PERMISSIONS
# if [ `whoami` != "root" ]; then
# echo "Insufficient permissions. Run as root."
@chew-z
chew-z / Pushover
Last active February 15, 2016 15:14
Send Notifications via Pushover (from Pythonista on iOS)
# coding: utf-8
# send Pushover notifications
import requests
import keychain
def pushNotification(message, title='', url='', url_title=''):
pushover_url = 'https://api.pushover.net/1/messages.json'
payload = {
'token': keychain.get_password('Pushover', 'token'),
@chew-z
chew-z / Google Chrome
Created February 18, 2016 02:59
Applescript for Automator activating Google Chrome (with built-in DNS disabled).
on run {input, parameters}
if application "Google Chrome" is running then
tell application "Google Chrome" to tell window 1 to close (tabs whose id is not (get id of active tab))
tell application "Google Chrome"
tell window 1 to make new tab with properties {URL:"http://localhost:8123/Chrome.html"}
end tell
else
do shell script "open -n -a 'Google Chrome' --args --disable-async-dns"
end if
@chew-z
chew-z / hosts2dnscrypt.py
Created February 19, 2016 10:41
Converts hosts file to DNSCrypt blacklist-domains file
#!/usr/bin/env python
# Takes hosts file and converts to DNSCrypt blacklist-domains file
# so you could block malicious hosts on DNSCrypt
# (when alternating to DNSCrypt instead of dnsmasq in my scenario)
# hosts file from https://github.com/StevenBlack/hosts
# See https://dnscrypt.org/ IP/domain names blocking
import re