Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
creatin' some stuff

Tomasz Ducin ducin

🛠️
creatin' some stuff
View GitHub Profile
@ducin
ducin / selection_sort.py
Created Feb 16, 2014
selection sort implementation
View selection_sort.py
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 Jul 18, 2014
example bash aliases used in linux environment
View .bash_aliases
alias cdprojects='cd ~/Projects'
alias pyc-remove='find . -name "*.pyc" -exec rm -rf {} \;'
timestamp2date() {
date -d@$1
}
alias ts2date=timestamp2date
View angular-ajax-spinner.html
<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
map positional arguments into options object
View argmapify.js
"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 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 / 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
You can’t perform that action at this time.