Skip to content

Instantly share code, notes, and snippets.

View rndD's full-sized avatar
🍎

Alexey Kalmakov rndD

🍎
View GitHub Profile
@rndD
rndD / deep_dict.py
Last active August 29, 2015 14:06
deep dict class
# -*- coding: utf-8 -*-
class deep_dict(dict):
def __init__(self, value=None):
if isinstance(value, dict):
for key in value:
self.__setitem__(
key,
deep_dict(value[key]) if isinstance(value[key], dict) else value[key]
)
else:
@rndD
rndD / go_for_ex
Created December 25, 2014 19:19
Exercise: Loops and Functions in go tour
package main
import (
"fmt"
"math"
)
const MAX_DELTA = 0.01
func isEnough(d float64) bool {
@rndD
rndD / go_slice_ex
Created December 26, 2014 02:47
Go lang Exercise: Slices
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
slice := make([][]uint8, dy)
for iy := range slice {
slice[iy] = make([]uint8, dx)
for ix := range slice {
@rndD
rndD / go_fib_ex
Created December 26, 2014 03:47
Go lang Exercise: Exercise: Fibonacci closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
x, y := 0, 1
return func() int {
new := x + y
@rndD
rndD / go_http_ex
Created December 28, 2014 16:16
A tour of GO: Exercise: HTTP Handlers
package main
import (
"fmt"
"log"
"net/http"
)
type String string
@rndD
rndD / go_binary_tree_ex
Created January 6, 2015 06:37
A tour of go: Exercise: Equivalent Binary Trees
package main
import (
"code.google.com/p/go-tour/tree"
"fmt"
"reflect"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
@rndD
rndD / parent_helper.html
Created February 15, 2015 11:38
parenthelper meteor example
{{deck}}
{{#each cards}}
{{#each brothers}}
{{> tmpl bro=this card=parentHelper deck=parentHelper.parentHelper.deck}}
{{/each}}
{{/each}}
#!/bin/bash
set -e
FROM=/home/media/Downloads/complete
TO=/home/media/Video
for file in $FROM/*; do
echo "Where move file :$file"
select item in Shows Films Skip; do
case "$item" in
@rndD
rndD / overlap_substrings.py
Created March 3, 2015 17:04
Поиск подстроки внахлест
# -*- coding: utf-8 -*-
import re
def count_substrings_re(string, substring):
substring_re = '(?=(%s))' % re.escape(substring)
return len(re.findall(substring_re, string))
def count_substrings(s, f):
ind = 1
count = 0
@rndD
rndD / shortest_bash_variable.bash
Created March 11, 2015 08:37
print shortest env variable by key (work only in bash, not sh)
for i in `env`; do
key=${i%=*}
[[ -z $short_env ]] && short_env=$key;
[[ ${#key} -lt ${#short_env} ]] && short_env=$key;
done
echo "Shortest env variable: $short_env"