Skip to content

Instantly share code, notes, and snippets.

View artursapek's full-sized avatar

Artur Sapek artursapek

View GitHub Profile
@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
@artursapek
artursapek / ra.sh
Last active December 10, 2015 16:09
Find/replace strings in files. WARNING: IT'S RECURSIVE!
#!/bin/sh
# Replace all instances of first string with second string. Use third arg as file(s) selector.
# If no selector is provided, do it to all files.
# Usage:
# ra artursapek ArturSapek
# => Replaces all instances of "artursapek" with "ArturSapek" in all files in this directory and its directories.
# Makes backups with names like index.html.1357352744.sedbak
# Required for sed to treat all ASCII as ASCII
@artursapek
artursapek / gr.sh
Created January 5, 2013 01:32
Easier recursive grep
#!/bin/sh
# Grep for a certain filetype recursively.
# Usage:
# gr headerBar html
# => All instances of "headerBar" in html files in this directory.
if [ -z "$2" ]
then
SELECTOR="*"
@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 / ants.py
Created October 14, 2012 03:36
Example of Ants logging usage
from ants.views import log_event
def ant_log(request, eventname, data={}):
# Sample wrapper using ants.log_event which always includes logged-in users' name and email, for instance...
if not request.user.is_anonymous():
data['user'] = '%s %s (%s)' % (request.user.first_name, request.user.last_name, request.user.email)
log_event(request, eventname, 'mysite', data)
def my_view(request):
# Your code...
@artursapek
artursapek / preload.coffee
Created September 5, 2012 21:09
preloading method
preload = (urls) ->
for url in urls
braces = url.match(/{\d\.\.\d}/g)
if braces
nums = braces[0].match(/\d/g)
expanded = []
for num in [nums[0]..nums[1]]
expanded.push url.replace(braces[0], num)
preload expanded
else