Skip to content

Instantly share code, notes, and snippets.

View artursapek's full-sized avatar

Artur Sapek artursapek

View GitHub Profile
@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 / 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
// Download a file to your machine
download = function(key){
// The CM download API call only requires a key as a parameter.
// Here we also include a second options parameter where "filename" tells
// the SDK we want to download the file to our local filesystem.
cm.download(key, {filename: key});
}
cm.destroy(key)
.on('complete', function(){
$('span[item="' + key + '"]').remove();
})
@artursapek
artursapek / dis.py
Created April 20, 2012 18:23
.jpeg distorting
import random
image = open('e.jpg', 'r')
lines = ''.join(image.readlines())
image.close()
ran = int(random.random() * len(lines))
for i in range(0, int(str(ran)[:1])/2):
ran = int(random.random() * len(lines))
t = lines[ran:ran+ran*6]
@artursapek
artursapek / fizzbuzz.py
Created February 22, 2012 21:22
fizz buzz
for i in range(0, 101):
d = {}
d[i % 3], d[i % 5] = 'Fizz', 'Buzz'
if 0 in d:
if len(d) == 1:
print 'FizzBuzz'
else:
print d[0]
else:
print i
@artursapek
artursapek / elements.css
Created February 22, 2012 20:20
Stylesheet for bandscape
/*
bandscape CSS
author: Artur Sapek
*/
html, body{
height:100%;
margin:0px;
overflow:hidden;
background:#F5F5F6;
@artursapek
artursapek / UIobjects.js
Created February 22, 2012 20:19
Basically all of the UI objects we were using for bandscape (the concert aggregator)
// DOM objects used in bandscape main view
// author: Artur Sapek
// bandscape 2011
// pre: nothing
// post: returns top-right control on the map, date and city (city doesn't do anything) and injects into DOM
function dateControl(){
var me = this;
this.dropdownFairGame = true;
this.keepopen = false;