Skip to content

Instantly share code, notes, and snippets.

View ducin's full-sized avatar
🛠️
creatin' some stuff

Tomasz Ducin ducin

🛠️
creatin' some stuff
View GitHub Profile
@ducin
ducin / selection_sort.py
Created February 16, 2014 20:05
selection sort implementation
def selection_sort(elements):
size = len(elements)
# loop over all elements excluding last one
for i in range(size - 1):
# find the smallest value in current range
min_index, min_value = i, elements[i]
for j in range(i + 1, size):
if elements[j] < min_value:
min_index, min_value = j, elements[j]
# swap i-th element with the smallest one
@ducin
ducin / .bash_aliases
Created July 18, 2014 10:40
example bash aliases used in linux environment
alias cdprojects='cd ~/Projects'
alias pyc-remove='find . -name "*.pyc" -exec rm -rf {} \;'
timestamp2date() {
date -d@$1
}
alias ts2date=timestamp2date
@ducin
ducin / angular-ajax-spinner.html
Created March 31, 2015 14:38
angular AJAX spinner
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-mocks.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-spinner/0.6.1/angular-spinner.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.0.1/spin.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', ['ngMockE2E', 'angularSpinner']);
@ducin
ducin / argmapify.js
Created May 16, 2015 12:25
map positional arguments into options object
"use strict";
// run `npm install introspect` before
var introspect = require('introspect');
function generateEmail(firstName, lastName, provider) {
return firstName + "." + lastName + "@" + provider;
}
var argMapify = function(fn, argValues, context) {
@ducin
ducin / ajax-ich.js
Last active December 15, 2015 14:48
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.
$(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 December 15, 2015 15:29
ICanHaz loop demo: example showing how to render looped data
$(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 April 7, 2013 15:27
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
#!/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 April 7, 2013 15:53
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.
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 / time_clock.py
Created July 10, 2013 21:28
benchmarking/timing python instructions
import time
start = time.clock()
for x in range(1,10000):
y = x**3
elapsed = time.clock() - start
print elapsed
@ducin
ducin / sum_dict_switch.py
Created July 10, 2013 21:12
summing up python dictionary values: add all values, where type='+' should be added, type='-' should be subtracted and other type should be ignored
# 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}]