Skip to content

Instantly share code, notes, and snippets.

@jaturken
jaturken / gist:3796439
Created September 27, 2012 21:00
Max in Scala
def max(xs: List[Int]): Int = {
def maxOfTwo(a:Int, b:Int) = if(a>b) a else b
def maxOfHeadAndTail(i: Int, l: List[Int]): Int = if (l.isEmpty) i else maxOfHeadAndTail(maxOfTwo(i, l.head), l.tail)
maxOfHeadAndTail(xs.head, xs.tail)
}
@jaturken
jaturken / gist:3953315
Created October 25, 2012 15:23
Tail recursion benchmarking
def non_tail_recursive_factorial(n)
if n < 2
1
else
n * non_tail_recursive_factorial(n-1)
end
end
def tail_recursive_factorial(n, r = 1)
if n < 2
@jaturken
jaturken / gist:3976117
Created October 29, 2012 19:52
Scala features cheatsheet

Cheat Sheet

This cheat sheet originated from the forum, credits to Laurent Poulain. We copied it and changed or added a few things.

Evaluation Rules

  • Call by value: evaluates the function arguments before calling the function
  • Call by name: evaluates the function first, and then evaluates the arguments if need be
@jaturken
jaturken / .zshrc
Created November 2, 2012 16:51
.zshrc
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
HISTSIZE=1000
SAVEHIST=1000
setopt append_history
setopt inc_append_history
setopt extended_history
setopt hist_find_no_dups
setopt hist_ignore_all_dups
setopt hist_reduce_blanks
@jaturken
jaturken / doe.sublime_snippet
Created November 12, 2012 14:31
Sublime do...end block autocompletion
<snippet>
<content><![CDATA[
do
${1:code}
end]]></content>
<description>do...end block</description>
<tabTrigger>doe</tabTrigger>
<scope>source.ruby</scope>
</snippet>
@jaturken
jaturken / Preferences.sublime-settings
Created November 14, 2012 08:15
Sublime user preferenses
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"highlight_line": true,
"caret_style": "wide",
"ensure_newline_at_eof_on_save": true
}
@jaturken
jaturken / users_to_pay_query.rb
Created March 7, 2013 16:42
UsersToPayQuery
class UsersToPayQuery
def self.find
# Select users who have no errors in groups, likes and shares, have wmr and have balanse to pay.
# A bit strange indentation. But it's easier to read this SQL in console with this indendation.
User.where("
NOT EXISTS(
SELECT id FROM shares
WHERE shares.error = 1
AND shares.declined = false
AND shares.user_id = users.id)
@jaturken
jaturken / application.js
Created March 25, 2013 08:52
moymir.api.users.hasAppPermission
params = 'app_id='+ mailru.app_id +
'ext_perm=stream' +
'method=users.hasAppPermission' +
'session_key=' + mailru.session.session_key +
'url=' + encodeURIComponent(data.url)
network_url = 'http://www.appsmail.ru/platform/api?method=users.hasAppPermission' +
'&app_id=' + mailru.app_id +
'&session_key=' + mailru.session.session_key +
'&sig=' + hex_md5(mailru.session.oid + params + mailru.private_key) +
@jaturken
jaturken / application.js
Last active December 15, 2015 09:09
moymir.api.stream.share
params = 'app_id='+ mailru.app_id +
'method=stream.share' +
'session_key=' + mailru.session.session_key +
'url=' + encodeURIComponent(data.url)
network_url = 'http://www.appsmail.ru/platform/api?method=stream.share' +
'&app_id=' + mailru.app_id +
'&session_key=' + mailru.session.session_key +
'&sig=' + hex_md5(mailru.session.oid + params + mailru.private_key) +
// '&sig=' + mailru.session.sig +
@jaturken
jaturken / moy_mir.rb
Last active December 15, 2015 10:09
check_share
def check_share?(url, uid)
# According to documentation from:
# http://api.mail.ru/docs/reference/rest/stream.getByAuthor/
request_url = "http://www.appsmail.ru/platform/api?" + request_params(url, uid)
responce = HTTParty.get(request_url)
end
private
def request_params(url, uid)