Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
creatin' some stuff

Tomasz Ducin ducin

🛠️
creatin' some stuff
View GitHub Profile
@ducin
ducin / ajax-ich.js
Last active Dec 15, 2015
ICanHaz.js `grabTemplates()` demo (see more at http://symfony-world.blogspot.com/2013/03/icanhazjs-grabtemplates-example.html). Example shows how you can load additional templates using ajax and reload ICanHaz container to use them. Note that the ajax call should be synchronous.
View ajax-ich.js
$(document).ready( function() {
$.ajax({
type: "GET",
dataType: 'text',
async: false,
url: "templates.html"
}).done(function(response) {
$("body").append(response);
ich.grabTemplates();
});
@ducin
ducin / ich-loop.js
Last active Dec 15, 2015
ICanHaz loop demo: example showing how to render looped data
View ich-loop.js
$(document).ready( function() {
$('#display').click(function () {
var data = [
{
"name": "Paul McCartney",
"email": "paul.mccartney@beatles.com",
"salary": "400"
},
{
"name": "John Lennon",
@ducin
ducin / concat-ich.sh
Created Apr 7, 2013
Concatenate all ICanHaz templates to one single file to make your project both load templates efficient/flexible and easy to maintain for many developers to work within a version control system
View concat-ich.sh
#!/bin/bash
path="src/main/web"
> "$path"/templates.ich
for file in "$path"/templates/*
do
cat "$file" >> "$path"/templates.ich
@ducin
ducin / ich-template-loader.js
Created Apr 7, 2013
ICanHaz templates loader object - load all your templates after the website has been initially rendered. See http://symfony-world.blogspot.com/2013/04/managing-lots-of-icanhaz-templates.html for details on concatenating template files.
View ich-template-loader.js
var TemplateLoader = {
path: 'templates/', // template files are stored in this directory
templates: ['file1', 'file2', 'file3'], // put all your template files here
fetchTemplate: function(path) {
$.ajax({
type: 'GET',
dataType: 'text',
async: false,
url: path
}).done(function(response) {
@ducin
ducin / sum_dict_switch.py
Created Jul 10, 2013
summing up python dictionary values: add all values, where type='+' should be added, type='-' should be subtracted and other type should be ignored
View sum_dict_switch.py
# define entries
entries = [{'type': '+', 'value': 9},\
{'type': '+', 'value': 12.3},\
{'type': '-', 'value': 4},\
{'type': '+', 'value': 0.89},\
{'type': '-', 'value': 2.65},\
{'type': '-', 'value': 14.3},\
{'type': '+', 'value': 6.8},\
{'type': 'unknown', 'value': 200}]
@ducin
ducin / time_clock.py
Created Jul 10, 2013
benchmarking/timing python instructions
View time_clock.py
import time
start = time.clock()
for x in range(1,10000):
y = x**3
elapsed = time.clock() - start
print elapsed
@ducin
ducin / bind.js
Last active Dec 20, 2015
binding "this" object to a function
View bind.js
// binding "this" object only (function arguments are ignored)
if (!Function.prototype.bind) {
Function.prototype.bind = function bind(thisObject) {
var fun = this;
return function() {
fun.apply(thisObject, arguments);
};
};
}
@ducin
ducin / bind.js
Created Jul 30, 2013
binding both "this" object and optionally arguments
View bind.js
// binding both "this" object and optionally arguments
if (!Function.prototype.bind) {
Function.prototype.bind = function bind(thisObject) {
var fun = this, boundArgs = Array.prototype.slice.call(arguments, 1);
return function() {
var allArgs = boundArgs;
if (arguments.length) {
allArgs = allArgs.concat(Array.prototype.slice.call(arguments));
}
@ducin
ducin / knotify.py
Created Aug 4, 2013
KNotify (KDE DBUS notifications); use it with: ./knotify.py "header" "content" (credited to http://www.documentroot.net/en/linux/knotify-python)
View knotify.py
#!/usr/bin/python
import sys, dbus
knotify = dbus.SessionBus().get_object("org.kde.knotify", "/Notify")
try: title, text = sys.argv[1:3]
except: print 'Usage: knotify.py title text'; sys.exit(1)
knotify.event("warning", "kde", [], title, text, [], [], 0, 0, dbus_interface="org.kde.KNotify")
@ducin
ducin / curry.js
Created Aug 6, 2013
currying is a mechanism to pre-fill arguments of a later function call
View curry.js
if (!Function.prototype.curry) {
(function () {
var slice = Array.prototype.slice;
Function.prototype.curry = function () {
var target = this;
var args = slice.call(arguments);
return function () {
var allArgs = args;
You can’t perform that action at this time.