Skip to content

Instantly share code, notes, and snippets.

View karolk's full-sized avatar
💭
cooking on gas

Karol K karolk

💭
cooking on gas
View GitHub Profile
@karolk
karolk / node-recorder.js
Last active August 29, 2015 13:57
Walks the DOM and records it as a JS object. Very useful for skimwords!
var generateNodeRecorer = function(forEach) {
function parseArgs(nodes, collecionOrNodeCallback, nodeCallback) {
//make sure single objects can be handled
if (!nodes.length) nodes = [nodes];
if (arguments.length === 0) {
throw new Error('Couldn\'t find nodes')
}
@karolk
karolk / limited-array.js
Last active August 29, 2015 14:05
good enough Limited Array (containing not more than n elements)
//limitations
//you can still use other methods like arr[index], Array.prototype.push(arr) and others to avoid limits
Array.prototype.trim = function(max) {
return this.splice(max, this.length-max)
}
Array.prototype.trimRight = function(max) {
return this.splice(0, this.length-max)
}
@karolk
karolk / index.html
Created July 27, 2015 22:36
mini spa
<!doctype html>
<script>
function $(selector) {
return document.querySelectorAll(selector)
}
function onClick(selector, callback) {
$("html")[0].addEventListener("click", function(event) {
(function() {
var css = [
'/css/default.css',
'/css/section.css',
'/css/custom.css'
],
i = 0,
link = document.createElement('link'),
head = document.getElementsByTagName('head')[0],
tmp;
var nodes = 0,
unique_handlers = [];
jQuery && jQuery('*').each(function() {
var ev = jQuery(this).data('events')
if (ev) {
for (var e in ev) {
eh_arr = ev[e];
nodes+=eh_arr.length;
for (var j=0, l=eh_arr.length; j<l; j++) {
eh = eh_arr[j].handler, sb = false;
@karolk
karolk / fb_likes.py
Created April 30, 2011 20:58
Check how many 'likes' a website's got if it uses Facebook like button
import urllib
import re
import sys
def fb_likes(url):
html = urllib.urlopen(url).read()
has_fb = re.search('<iframe src=\"http\:\/\/www.facebook.com', html)
if has_fb:
fb_iframe_url = re.search('<iframe src="(http\:\/\/www.facebook.com\S+)"', html).group(1)
fb_html = urllib.urlopen(fb_iframe_url).read()
@karolk
karolk / beep_number.py
Created October 25, 2011 19:26
play a little tune based on any number (Windows)
import time
import winsound #only works on windows, any similar APIs on Mac/Linux?
def beep_number(number, length=200):
#sounds frequencies in hertz, starting from middle C and going up to high E
sounds = [261, 294, 330, 350, 392, 440, 494, 523, 587, 659]
i=0
while i<len(number):
winsound.Beep(sounds[int(number[i])],length)
@karolk
karolk / ObjectCreate.js
Created December 2, 2011 16:13
Object.create wrapper with shorter property descriptor syntax and graceful handling for browsers not supporting it
function ObjectCreate(proto, properties) {
var propDesc = {}, p, pd, pdStr, ES5 = !!(Object.create && Object.defineProperties);
if (!ES5) {
var F = function() {};
F.prototype = proto;
var o = new F();
}
for (p in properties) {
pd = properties[p], pdStr = pd.pd.toLowerCase();
if (ES5) {
@karolk
karolk / LICENSE.txt
Created January 3, 2012 18:29 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Karol Kowalski <http://github.com/karolk>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@karolk
karolk / jsrpc.js
Created March 9, 2012 19:52
rpc in JavaScript
/*
Call certain JS functions in a controlled way by passing the name in the URL.
This can be likened to XSS but done in a controlled way
#Possible use case
Let's assume there is a social networking site having a feature 'invite me for lunch'.
Unfortunately the feature is not very well visible in the GUI. Assuming there is a JS
function inviteForLunch(ISODate) defined on the page people could create links on their