Skip to content

Instantly share code, notes, and snippets.

View chew-z's full-sized avatar
🇦🇺

Robert J. chew-z

🇦🇺
View GitHub Profile
@chew-z
chew-z / .zshrc
Created August 27, 2016 09:54
Lazy loading virtualenv in zsh
# virtualenvwrapper
# lazy loading saves on shell startup time
workon() {
[ -z "$PROJECT_HOME" ] && {
unset -f workon;
export WORKON_HOME=$HOME/.virtualenvs;
export PROJECT_HOME=$HOME/Documents/Python;
source /usr/local/bin/virtualenvwrapper.sh
}
workon "$@"
@chew-z
chew-z / serve_files.py
Created July 19, 2016 03:38
Small but smart script for serving files in Pythonista iOS
#coding: utf-8
# python 3
# This script is an editor action, called "Serve Files." It has three improvements over existing implementations:
# Serve every file from the directory of your script at its filename
# Serve a zip of the entire directory in which your script is contained at /. This is useful for copying a lot of files to a computer at once
# Printing your local IP to the console, to make it easier to see where you should go on your computer
# It will also clean up the zip it creates after you stop the server.
import os
import shutil
@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'),