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 / .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 / 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 / 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 / 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 / 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 / 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 / .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 / Open in iTerm2.AppleScript
Created August 31, 2016 12:56
Opens folder selected in Finder in iTerm2 - current tab or when busy creates new tab. I am using that as application attached to Finder.
on run {input, parameters}
if input is not in {{}, {""}, ""} then
tell application "Finder"
set my_file to first item of input
set filetype to (kind of (info for my_file))
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
-- http://stackoverflow.com/a/6881524/640517
if filetype is "Folder" or filetype is "Volume" then
set dir_path to quoted form of (POSIX path of my_file)
else
@chew-z
chew-z / finder.sh
Created August 31, 2016 13:05
open current folder in Finder
#!/usr/bin/env zsh
# open current folder in Finder
osascript -e'on run {arg}
set the_folder to POSIX file (POSIX path of arg)
tell application "Finder"
activate
if exists window 1 then
set target of window 1 to the_folder
else
@chew-z
chew-z / hex_256.pl
Created September 2, 2016 02:26
Color converter HEX to term256
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);
use Color::ANSI::Util qw(
rgb_to_ansi256
);
say "Throw me hex# and I will throw back ansi 256 color";