Skip to content

Instantly share code, notes, and snippets.

View snahor's full-sized avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
@snahor
snahor / scrollbars-dimensions.js
Last active December 10, 2015 14:08
Get scrollbars dimensions. Taken from http://stackoverflow.com/a/8221501/94746
function getScrollBarDimensions() {
var elm = document.documentElement.offsetHeight ? document.documentElement : document.body,
curX = elm.clientWidth,
curY = elm.clientHeight,
hasScrollX = elm.scrollWidth > curX,
hasScrollY = elm.scrollHeight > curY,
prev = elm.style.overflow,
r = { vertical: 0, horizontal: 0 };
if ( !hasScrollY && !hasScrollX )
@snahor
snahor / timeit.py
Last active December 14, 2015 20:38
def timeit(fn):
def time_fn(*arg, **kw):
import time
now = time.time()
fn(*arg, **kw)
total = time.time() - now
print "total time for %s: %d" % (fn.__name__, total)
return time_fn
@snahor
snahor / gist:5550458
Created May 9, 2013 20:42
Lorem ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida, nisl consectetur dignissim euismod, ante tortor rutrum libero, ac euismod mauris elit non augue. Morbi vel placerat mi. In enim metus, commodo nec adipiscing eget, vestibulum ut turpis. In lacinia justo sit amet erat tristique in pharetra nisl condimentum. Vivamus at diam ac nibh placerat egestas id sit amet velit. Mauris sed enim eu metus congue hendrerit. Duis sem nibh, rutrum venenatis pretium eget, auctor sit amet odio. Vivamus nisl ligula, interdum vitae scelerisque et, feugiat quis ipsum. Morbi vel dolor ut nunc pharetra placerat. Pellentesque id quam lacus, ut placerat purus.
from threading import Thread
import cProfile
import pstats
def enable_thread_profiling():
'''Monkey-patch Thread.run to enable global profiling.
Each thread creates a local profiler; statistics are pooled
to the global stats object on run completion.'''
#!/bin/sh
sudo apt-get update
sudo apt-get install openjdk-6-jre
sudo apt-get install openjdk-6-jdk
sudo wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
sudo apt-get install ant
import os
localDir = os.path.dirname(__file__)
absDir = os.path.join(os.getcwd(), localDir)
import cherrypy
class FileDemo(object):
def index(self, myFile=None, derp_cv=None, **kwargs):
if cherrypy.request.method == "POST":
@snahor
snahor / datepicker.js
Last active December 20, 2015 06:09
angularjs datepicker
angular.module('appApp')
.directive('datePicker', function ($timeout) {
return {
restrict: 'E',
replace: true,
scope: { ngModel: '=' },
template:
'<div class="controls">' +
'<select class="span2">' +
'</select> / ' +
'use strict';
var onlineStatusApp = angular.module('onlineStatusApp', []);
onlineStatusApp.factory('onlineStatus', ["$window", "$rootScope", function ($window, $rootScope) {
var onlineStatus = {};
onlineStatus.onLine = $window.navigator.onLine;
onlineStatus.isOnline = function() {
@snahor
snahor / xsrf_cookie.py
Created August 6, 2013 22:24
Cherrypy tool to check xsrf tokens.
@snahor
snahor / 41.go
Last active December 22, 2015 02:09
golang tour exercises
package main
import (
"strings"
"code.google.com/p/go-tour/wc"
)
func WordCount(s string) map[string]int {
m := make(map[string]int);
for _, vv := range strings.Fields(s) {