Skip to content

Instantly share code, notes, and snippets.

View aherok's full-sized avatar

Andrzej Herok aherok

View GitHub Profile
/*
CSRF AJAX HANDLING
*/
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
@aherok
aherok / BootstrappedMixin
Last active December 20, 2015 17:59
BootstrappedMixin for form - adds Bootstrap3.0 classes & placeholder
class BootstrappedMixin(object):
def __init__(self, *args, **kwargs):
super(BootstrappedMixin, self).__init__(*args, **kwargs)
for field_name in self.fields:
field = self.fields.get(field_name)
attrs = {'class': 'form-control'}
if field and isinstance(field.widget, forms.TextInput):
attrs.update({'placeholder': field.label})
field.widget.attrs = attrs
@aherok
aherok / busy-indicator.js
Created January 15, 2014 13:36
AngularJS module that displays "please wait" message on time-taking actions. First attempt, yet working.
/**
* Indicator module - fades HTML content and displays "please wait" message on time-taking actions
* usage:
*
* html:
* <div busy-indicator="main-progress">
*
* js:
* busyIndicator.add("main-progress");
* // do some time-taking actions...
@aherok
aherok / pg_locks.sql
Created April 11, 2014 13:01
display locking queries in pqsql. experimental.
SELECT
bl.transactionid,
bl.mode,
ka.query,
ka.query_start,
ka.state_change,
ka.state,
ka.pid
FROM pg_locks bl
@aherok
aherok / fcpxml.py
Created March 25, 2015 21:02
Very robust .fpcxml -> .srt file converter
import os
from sys import argv
from xml.etree.ElementTree import parse
from pysrt import SubRipFile, SubRipItem, SubRipTime
def _mili_to_frame(secs):
"""
Convert "miliseconds" to frame count, e.g. if start time is 2.5s,
then its 2 secs and 12 frames, so function will return 2.12. Magic :)
Verifying that +aherok is my blockchain ID. https://onename.com/aherok
@aherok
aherok / .eslintrc.js
Last active April 4, 2017 18:36
eslint codestyle config
module.exports = {
// enable parsing ES5 code
/*
"parserOptions": {
"ecmaVersion": 5,
},
*/
"parser": "babel-eslint", // needed to properly parse ES7 features, e.g. 'static' declarations
@aherok
aherok / packages.json
Created March 28, 2017 12:05
stylelint
{
"devDependencies": {
"stylelint": "^7.9.0",
"stylelint-config-standard": "^16.0.0"
},
}
@aherok
aherok / .bash_profile
Created April 18, 2017 19:47
git prompt in bash
#
# PROMPT + GIT INFO
#return value visualisation
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1="\$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]\h'; else echo '\[\033[01;32m\]\u@\h'; fi)\[\033[01;34m\] \w \[\033[00m\]\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

Keybase proof

I hereby claim:

  • I am aherok on github.
  • I am aherok (https://keybase.io/aherok) on keybase.
  • I have a public key ASBf6QXuVb8_a2Kvb-0hmJGYpeYANErWsGKuDJjuqu3Vlgo

To claim this, I am signing this object: