Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View artursapek's full-sized avatar

Artur Sapek artursapek

View GitHub Profile
// Originally taken from https://github.com/mgtitimoli/await-mutex
class Mutex {
constructor() {
this._locking = Promise.resolve();
this._locked = false;
}
isLocked() {
return this._locked;
@artursapek
artursapek / whitelist.js
Created October 31, 2012 02:44
Character whitelisting for input field
(function($){
// Bind to an input field. Provide chars, a string of characters.
// Now only those characters can be typed in.
$.fn.whitelist = function(chars){
var $this = $(this), chars = chars.split('');
$this.keypress(function(e){
if (chars.indexOf(String.fromCharCode(e.which)) == -1){ return false; }});
return $this;
};
}(jQuery));
@artursapek
artursapek / install-phantomjs.sh
Created June 8, 2015 15:50
Installing phantomjs 2.0 on Ubuntu 14.04
# Installing Phantomjs 2.0 can be kind of a pain. Their website claims they don't have
# any Linux binaries to share because of an unresolved dependency issue.
# However, someone going by eugene1g shared some binaries that he build that seem
# to work given a small amount of apt-get setup. https://github.com/eugene1g/phantomjs
sudo su
apt-get update
apt-get install unzip libfontconfig libjpeg-turbo8
cd /tmp
# for tmux status bar
info = `pmset -g batt`.split("\n")
perc = info[1].split(" ")[1].gsub(";","")
charging = info[0].include? "AC Power"
as_f = perc.to_f
if as_f > 75
status = "green"
bars = 4
elsif as_f > 50
status = "yellow"
package btce
import (
"bytes"
"net/http"
"net/url"
"time"
"crypto/sha512"
"crypto/hmac"
"strconv"
@artursapek
artursapek / remove_css_classes.py
Created November 9, 2013 19:42
Super primitive. Expects one class per line. Did the job
from subprocess import Popen, PIPE
import sys
import re
import os
APP_DIR = '/Users/artur/Work/Codecademy-dev/Codecademy/app/'
VIEWS = ['erb', 'mustache', 'haml']
def search(query, filetypes=[]):
args = ['grep', '-r', '-I', '--exclude=".git"']
@artursapek
artursapek / southwest.sh
Last active December 22, 2015 02:18
Checks in for your Southwest flight. Schedule this for a little bit before your 24-hour time and it will run until it succeeds, and get you an early boarding number and therefore a good seat.
# POSTs your confirmation key, first name, and last name
# to Southwest.com check-in endpoint over and over
# until it doesn't see the 24-hour error.
# In testing I never got rate-limited or blocked
# but I didn't let it run for very long at a time
# so use at your own risk. :)
# Six-character SW confirmation token here
CONF=AB1234
. $HOME/.bash_profile
cd $HOME/Codecademy/app
check_usage () {
while read data
do
PARTIAL_NAME=$(echo $data | sed 's/views\///g' | sed 's/\/\_/\//g' | sed 's/\..*//g')
PARTIAL_LOCAL_NAME=$(echo $PARTIAL_NAME | sed 's/.*\///g')
for own ind, char of as
# Iterate over the characters in a-split
if matching
# So far we have only found matching chars...
if bs[ind] == char
# If they're still matching then great
continue
else
# Uh-oh! We've found the first mistmatch!
matching = false
@artursapek
artursapek / clsb.sh
Created January 5, 2013 02:31
Quickly remove all .sedbak backup files. RECURSIVE!
#!/bin/sh
# Remove all .sedbak files (sed backup files)
find . -name "*.sedbak" -print0 | xargs -0 rm