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 / check-hijacking.sh
Created November 21, 2016 15:05
Check router connection hijacking (captive portal)
#!/usr/bin/env zsh
# adapted from Alterstep dnscrypt-proxy OSX client
try_resolution() {
exec alarmer 5 dig +tries=2 +time=3 +short github.com | egrep '^192[.]30[.]' > /dev/null 2>&1
}
try_http_query() {
exec alarmer 5 curl -L --max-redirs 5 -4 -m 5 --connect-timeout 5 -s \
http://icanhazip.com/ 2>/dev/null | \
@chew-z
chew-z / captive.sh
Last active November 21, 2016 15:11
Login into captive portal
#!/usr/bin/env zsh
if check-hijacking; then
echo "The router doesn't hijack HTTP queries"
else
echo "The router hijacks HTTP queries - DNSCrypt is likely to be blocked"
# kill/stop DNSCrypt
networksetup -getcurrentlocation
networksetup -switchtolocation 'Captive portal'
@chew-z
chew-z / mail.vim
Created October 17, 2016 14:14
My mail.vim for using mutt with vim. Handles linebreaks, included email etc
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
" safe and simple
setlocal nobackup
setlocal noswapfile
setlocal nowritebackup
@chew-z
chew-z / 256.pl
Created September 6, 2016 13:38
Prints Lorem ipsum with fore- and background colors
#!/usr/bin/perl
use Term::ExtendedColor qw(:all);
use strict;
use warnings;
use feature qw(say);
say "Throw me two numbers or two color names separated by space(s)";
while (<>) {
# print $_;
@chew-z
chew-z / by_line.pl
Last active September 6, 2016 13:27
Prints lines form mutt colorfile in designated colors. Usefull when tuning colors for mutt
#!/usr/bin/perl
# This simple perl scripts prints lines from mutt colorfile
# in actual designated colors.
# I have created that script for finetuning my mutt with
# iTerm color themes.
# I am using here mix of little known library Term::ExtendedColors
# for extended colors and escape codes for base16 colors.
# Term::ExtendedColors is weird with base16
# It looks fuzzy but works!
# Actual colors depend on definitions in terminal color palette first of all
@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";
@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 / 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 / .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