Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am miloshadzic on github.
  • I am miloshadzic (https://keybase.io/miloshadzic) on keybase.
  • I have a public key ASA86E5jWs3Z519MuxyoN4NYOyoTMbvfkA65CjAoRlvALQo

To claim this, I am signing this object:

@miloshadzic
miloshadzic / bash
Created June 19, 2016 10:58
seedbox backup cmd
rsync -vrh --progress -e "ssh -T -c arcfour -o Compression=no -x" <source> <destination>
#reduce(function, sequence)
print reduce(lambda x, y: x+y, range(1,11))
def red(funct, seq):
for x in seq: #do this for every x in this list
return funct(seq) # ovde ti je greska zbog toga sto ce ovaj return da vrati
# rezultat poziva funct(seq) vec na prvom elementu. Probaj da prvo napravis
# promenljivu u kojoj ces drzati rezultat. To ti je "akumulator". Dodatni hint
@miloshadzic
miloshadzic / gist:6179055
Created August 7, 2013 21:46
What am I doing wrong?
/// Retrieves a value for the given key. A passed default value is
/// returned if the key is not present.
pub fn get_or_default<'a>(&'a self, k: &K, default: &V) -> &'a V {
match self.find(k) {
Some(v) => v,
None => default
}
}
pub fn get<'a>(&'a self, k: &K) -> &'a V {
match self.find(k) {
Some(v) => v,
None => fail!("No entry found for key: %?", k),
}
}
def score dice
{1 => 100, 2 => 0, 3 => 0, 4 => 0, 5 => 50, 6 => 0}.map do |(n, score)|
occurences = dice.count n
(occurences / 3) * (n == 1 ? 1000 : n * 100) + (occurences % 3) * score
end.reduce :+
end
class A;end
module B
def hello
puts "hello"
end
end
A.hello => NoMethodError
@miloshadzic
miloshadzic / gist:4838144
Created February 13, 2013 01:45
Clojure string joining
user=> (clojure.string/join ["a" "b" "c" "d"])
"abcd"
user=> (clojure.string/join ", " ["a" "b" "c" "d"])
"a, b, c, d"
# AMD require sugared syntax
# http://requirejs.org/docs/whyamd.html#sugar
# Works better when there are many dependencies
# Before
define ['backbone'], (Backbone) ->
class Table extends Backbone.model
# After
define (require) ->
({
baseUrl: 'app',
out: 'build/main.js',
optimize: 'uglify2',
name: 'libs/almond',
include: ['main'],
exclude: ['coffee-script'],
stubModules: ['cs', 'text'],