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 / dropbox_file_picker3.py
Created July 19, 2016 03:34
Pythonista's Dropbox File Picker adapted to python 3
#coding: utf-8
#python 3
from __future__ import absolute_import
import keychain
import requests
from urllib.parse import quote
import os
import ui
@chew-z
chew-z / scrap__web.py
Created March 8, 2016 11:40
Scrap web page to markdown (in Pythonista on iOS) and put reult into new draft with Drafts4
#scraps text from web page, puts in new Draft
import sys
import requests
import html2text
import clipboard
import webbrowser
import urllib
def get_page(url):
try:
@chew-z
chew-z / Moebius.py
Last active October 7, 2017 10:35
Prime # counting algos, each better or more pythonic then previous
#!/usr/bin/env python3
# coding: utf-8
# various algos counting prime numbers < N
# each better or more pythonic then previous
import itertools
import numpy as np
import datetime
from operator import mul
from functools import reduce
@chew-z
chew-z / sleep
Last active November 13, 2016 06:05
sleep script for sleepwatcher (OSX)
#!/bin/bash
echo "I feel like napping right now..."
echo $(date +"%c")
ADAPTER=$(networksetup -listallhardwareports | grep -A1 Wi-Fi | awk '/Device:/ {print $2}')
CONN=$(networksetup -getairportnetwork "$ADAPTER")
echo "$CONN"
# switch OFF WiFi first
networksetup -setairportpower "$ADAPTER" off
@chew-z
chew-z / .wakeup
Last active January 29, 2017 11:48
Wakeup script for sleepwatcher
#!/bin/bash
echo "I've been napping. Waking up now..."
echo $(date +"%c")
# Switch WiFi ON
# ADAPTER=en0
ADAPTER=$(networksetup -listallhardwareports | grep -A1 Wi-Fi | awk '/Device:/ {print $2}')
echo "$ADAPTER"
# check wifi MAC
MAC=$(/usr/local/bin/spoof-mac list --wifi)
@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
@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 / 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 / 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 / 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/