Skip to content

Instantly share code, notes, and snippets.

View ironsmile's full-sized avatar

Doychin Atanasov ironsmile

View GitHub Profile
@ironsmile
ironsmile / gematria.py
Last active February 2, 2020 11:53
Gametria program for BG and Hebrew
#!/usr/bin/env python
import argparse
import math
import sys
alphabets = {
"he": {
"א": 1,
"ב": 2,
@ironsmile
ironsmile / aggregator.go
Last active August 29, 2015 14:08
ranging over channel after selecting from it
for {
select {
case elem := <-a.traffChan:
a.aggregateTraff(elem.header, elem.body)
//!TODO maybe return elem to the pool
case elem := <-a.hitChan:
a.aggregateHit(elem.header, elem.body)
//!TODO maybe return elem to the pool
case <-a.stopChan:
close(a.traffChan)
@ironsmile
ironsmile / preg_bug.php
Last active August 29, 2015 14:08
Do you spot the bug?
<?php
$string = 'lalalalala';
$string = preg_replace('/(a+)/', 'many-a', $string);
// continue my work with string
// hopefully it is "lmany-almany-almany-almany-almany-a"
?>
@ironsmile
ironsmile / node-ubuntu.sh
Created October 16, 2014 17:54
Ubuntu nodejs resolution
[~/playfield]
iron4o$ which js
/usr/bin/js
[~/playfield]
iron4o$ ls -lh /usr/bin/js
lrwxrwxrwx 1 root root 20 Feb 6 2012 /usr/bin/js -> /etc/alternatives/js
[~/playfield]
iron4o$ ls -lh /etc/alternatives/js
lrwxrwxrwx 1 root root 13 Feb 6 2012 /etc/alternatives/js -> /usr/bin/node
[~/playfield]
@ironsmile
ironsmile / git_pull_all.sh
Last active August 29, 2015 14:04
Pull from all git repositories
#!/bin/bash
cd $(dirname `readlink -f $0`)
git_dirs=`find . -maxdepth 1 -type d | grep -v -E '^\.$'`
for git_dir in $git_dirs
do
echo "Entering $git_dir"
cd "$git_dir"
@ironsmile
ironsmile / progress.html
Created September 26, 2013 14:42
HTML 5 progress example
<!DOCTYPE html>
<html>
<header></header>
<body>
<progress value="5" max="13" id="prog"></progress>
<script>
_t = null;
function progress () {
if (_t) {
clearTimeout(_t);
@ironsmile
ironsmile / repeater.sh
Created September 9, 2013 13:34
repeats a command as long as its execution is more than 3 seconds
#!/bin/bash
while [[ true ]]; do
echo "[`date`] Repeating $1"
START=`date +%s`
$1
END=`date +%s`
DURATION=`echo "$END-$START" | bc`
#!/bin/sh
if [ $# -lt 1 ]
then
echo "Usage: $0 remote.host.name [port]"
exit 1
fi
REMHOST=$1
REMPORT=${2:-443}
@ironsmile
ironsmile / gist:1759915
Created February 7, 2012 14:23
distrustful function
<?php
// freakishly distrustful about its arguments function
function document_mark_as_sent($invoices){
global $page, $db;
if(empty($invoices)){ return; }
if(!is_array($invoices)){ $invoices = array((int)$invoices); }
if(!is_object($page) or !is_object($db)){ return; }
if(!isset($page->firm) or !$page->firm){ return; }
if( is_object($invoices[0]) ){ // значи е масив от Invoice обекти
$invoices = array_map(create_function('$i', 'return $i->id;'), $invoices);
@ironsmile
ironsmile / gist:997849
Created May 29, 2011 15:14
ctimer for blago
#include <iostream>
#include <sys/time.h>
int main (int argc, char * const argv[]) {
timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
int * arr = new int[100000000];