Skip to content

Instantly share code, notes, and snippets.

View JiriChara's full-sized avatar
🇩🇪
Munich

Jiří Chára JiriChara

🇩🇪
Munich
View GitHub Profile
@JiriChara
JiriChara / gist:2163848
Created March 22, 2012 20:36
Processing options and parameters with getopts
#!/bin/bash
# processing options and parameters with getopts
while getopts :ab:cd opt
do
case "$opt" in
a) echo "Found the -a option";;
b) echo "Found the -b option, with value $OPTARG";;
c) echo "Found the -c option";;
d) echo "Found the -d option";;
@JiriChara
JiriChara / gist:3697487
Created September 11, 2012 10:31
ALL CREDIT CARD PIN CODES IN THE WORLD
for i in 0..9999
if(i % 9 == 0)
printf("%04d \n", i)
else
printf("%04d \t", i)
end
end
@JiriChara
JiriChara / gist:3705457
Created September 12, 2012 09:14
ALL CREDIT CARD PIN CODES IN THE WORLD (node.js)
function p(a){return (5+a+"").slice(-5)};for(i=0;i<=9999;i++){i%9?process.stdout.write(p(i+"\t")):process.stdout.write(p(i+"\n"))}
function z(g){process.stdout.write(g)}function p(a){return (5+a+"").slice(-5)};for(i=0;i<=9999;i++){i%9?z(p(i+"\t")):z(p(i+"\n"))}
@JiriChara
JiriChara / gist:4026567
Created November 6, 2012 18:30
Ubuntu 12.04 Install
sudo apt-get update
sudo apt-get upgrade
sudo reboot
sudo apt-get install nvidia-current
sudo reboot
sudo apt-get install ubuntu-restricted-extras
sudo apt-get install mercurial
hg clone https://vim.googlecode.com/hg/ ~/vim
cd ~/vim/src
sudo apt-get install ncurses-term
@JiriChara
JiriChara / gist:4075031
Created November 14, 2012 21:42
Javascript Currying
function schonfinkelize(fn) {
var slice = Array.prototype.slice,
storedArgs = slice.call(arguments, 1);
return function () {
var newArgs = slice.call(arguments),
args = storedArgs.concat(newArgs);
return fn.apply(null, args);
};
}
@JiriChara
JiriChara / gist:4081280
Created November 15, 2012 21:08
Javascript Namespaces
var MYAPP = MYAPP || {};
MYAPP.namespace = function (ns_string) {
var parts = ns_string.split('.'),
parent = MYAPP,
i;
// strip redundant leading global
if (parts[0] === "MYAPP") {
parts = parts.slice(1);
}
@JiriChara
JiriChara / gist:4526107
Created January 13, 2013 20:36
Parsing IRC messages in Ruby
result = {}
parts = message.split(' ')
result[:prefix] = parts.shift.gsub(/^:/, "") if parts[0] =~ /^:/
result[:command] = parts.shift
result[:params] = parts.take_while { |x| x[0] != ":" }
if result[:params].size < parts.size
full_string = parts.slice(result[:params].size..-1).join(" ")
full_string.gsub!(/^:/, "")
require 'eventmachine'
module Mplayer
def receive_data(data)
end
end
class Player
def initialize
@io = EM.popen("mplayer -noconsolecontrols -nolirc -idle -slave", Mplayer)
@JiriChara
JiriChara / gist:4622137
Last active December 11, 2015 15:38
EventMachine respond to one character from stdin
require "eventmachine"
require "highline/import"
def get_user_input
input = HighLine.new
c = ask('') { |q| q.character = true; q.echo = false }
# Do something
print c
get_user_input
end
@JiriChara
JiriChara / gist:5141311
Created March 12, 2013 09:01
Update all submodules to origin/master
git submodule -q foreach git pull -q origin master