Skip to content

Instantly share code, notes, and snippets.

View gtklocker's full-sized avatar

Kostis Karantias gtklocker

View GitHub Profile
@gtklocker
gtklocker / linked-lists.c
Created June 1, 2012 19:11
Doubly linked list implementation in C
/*
* An implementation of doubly linked lists in C.
*
* API:
* * init()
* Initializes a doubly linked list and returns it.
* * push( list, value )
* Appends a new element with value to the list.
* * destroy( list, value )
* Destroys the first element with value found in the list.
@gtklocker
gtklocker / password.cpp
Created August 3, 2012 19:29
Password Generator
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
int main( int argv, char *argc[] ) {
assert( argv > 1 );
const int N = atoi( argc[ 1 ] ); // Password length
char i, randChar;
@gtklocker
gtklocker / gist:3453371
Created August 24, 2012 17:45
Z-order in 9 lines of C
// It only z-orders 8-bit numbers correctly but you can modify
// the for loop so that it works for more bits (maybe replace 8
// with 16 or 32, 64 is probably a bad idea unless you have a
// 128-bit system) and the return/ret and parameter type accordingly.
int zOrder( int lhs, int rhs ) {
int bit, ret;
for ( ret = 0, bit = 0; bit < 8; ++bit ) {
ret |= ( ( ( lhs & 1 ) << 1 ) | ( rhs & 1 ) ) << ( bit << 1 );
lhs >>= 1;
rhs >>= 1;
@gtklocker
gtklocker / gist:3848312
Created October 7, 2012 12:53
Minimal Greek to Greeklish converter (capital letters only)
# coding: utf-8
import sys
alphabet = {
'Α': 'A',
'Β': 'B',
'Γ': 'G',
'Δ': 'D',
'Ε': 'E',
'Ζ': 'Z',
@gtklocker
gtklocker / compute.py
Last active August 29, 2015 13:56
Basic calculator
import operator
def compute(expression):
fn = {
'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.div
}
# could use fn.keys but dictionaries are orderless
Verifying that +gtklocker is my openname (Bitcoin username). https://onename.com/gtklocker
@gtklocker
gtklocker / timing.js
Created April 25, 2015 07:19
Timing wtf
var before = +new Date();
console.log("execution took", +new Date() - before, "ms");
// execution took 13 ms
@gtklocker
gtklocker / style.md
Last active August 29, 2015 14:21
Coding Style by dionyziz

Why?

Although [coding style](w:Coding style "wikilink") might seem a minor thing for novice programmers, it really is of utter importance when writing code for a medium-sized or big project. If you code alone, it still is vital to follow prespecified coding standards in order to achieve a better level of code readability for yourself. If you code as a member of a team, not following strict style conventions is completely out of the question. Considering that a project which you're the only programmer for might grow into a team project in the future makes it a crucial matter to follow certain coding standards, as it is a hard and time-consuming procedure to port code to new coding style. And, although many coding style rules can be automated and applied using a beautifier script, many rules cannot (as they fall into the programmer's judgment), and a lot of rules are broken by these scripts. In addition, many programmers, including myself, do not like using these scripts and believe that using a beautiful

#!/bin/bash
execgit() {
exec git "$@"
}
if [ "`git rev-parse --is-inside-work-tree`" != "true" ]; then
execgit
fi
#!/bin/bash
OLD_CASK_PATH="/opt/homebrew-cask/Caskroom"
NEW_CASK_PATH="/usr/local/Caskroom"
APP_DIRS=( "$HOME/Applications" "/Applications" )
mkdir -p $NEW_CASK_PATH
chown -R `whoami`:staff $NEW_CASK_PATH
for app_dir in "${APP_DIRS[@]}"; do