Skip to content

Instantly share code, notes, and snippets.

View srstanic's full-sized avatar

Srđan Stanić srstanic

View GitHub Profile
@srstanic
srstanic / js_handlers.py
Created July 6, 2012 12:28
Use it to add Cancel buttons to Django forms, or to open any given URL on button click.
'''
templatetags module
'''
from django import template
register = template.Library()
@register.simple_tag
def go_to_url(url):
return "window.location='" + url +"'; return false;"
@srstanic
srstanic / NewView.js
Created September 25, 2012 16:40
Overriding Backbone.View constructor example
/**
* Store view's clientId to the root element's $.data object.
*/
var MyView = Backbone.View.extend({
constructor: function(){
var view = this,
render;
Backbone.View.prototype.constructor.apply(view, arguments);
@srstanic
srstanic / fmkill.sh
Last active December 9, 2015 23:48
Kill zombie processes Foreman started
#!/bin/bash
kill -9 `lsof -P -i :5000 | sed -n 's/python *\([0-9]*\).*\:5000.*/\1/p'`
@srstanic
srstanic / script_load.js
Created January 11, 2013 19:17
Dom manipulation functions useful for dynamically loading scripts.
window.dom = {
createScriptElement: function(url, async) {
var script = document.createElement("script");
script.setAttribute("src", url);
if (async !== undefined) {
script.async = async;
}
return script;
},
findScriptElementById: function(id) {
PS1='\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h: \[$(tput sgr0)\]\[\033[38;5;6m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;15m\] \\$\[$(tput sgr0)\] '
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
source /usr/local/git/contrib/completion/git-completion.bash
source /usr/local/git/contrib/completion/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
PS1='\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h: \[$(tput sgr0)\]\[\033[38;5;6m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]\[$(tput sgr0)\]\[\033[38;5;13m\]$(__git_ps1 " (%s)")\[$(tput sgr0)\]\[\033[38;5;15m\] \\$\[$(tput sgr0)\] '
fi
alias rm-orig="find . -name '*.orig' -delete"
#!/bin/bash
IFS='.' read -a filename_parts <<< "$1"
name=${filename_parts[0]}
ext=${filename_parts[1]}
sips -Z 66 $1 --out $name"-66."$ext
sips -Z 44 $1 --out $name"-44."$ext
@srstanic
srstanic / RoundedBorderButton.swift
Last active March 30, 2017 21:02
RoundedBorderButton.swift
import UIKit
@IBDesignable
class RoundedBorderButton: UIButton {
@IBInspectable dynamic var cornerRadius: CGFloat = 20.0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = true
}
@srstanic
srstanic / load-gif-in-background.js
Created March 24, 2017 19:23
Load gif in background
var gifs = {
'imageElementId': 'http://example.com/myimage.gif'
}
function getUpdateImageSrcFunc(imageId) {
return function() {
document.getElementById(imageId).src = this.src;
}
}
for (var imageId in gifs) {
var gifSrc = gifs[imageId]
import UIKit
class KeyboardAvoider {
init(for scrollView: UIScrollView) {
self.scrollView = scrollView
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(
self,