Skip to content

Instantly share code, notes, and snippets.

View sdolidze's full-sized avatar

Sandro Dolidze sdolidze

View GitHub Profile
import {
zipObj,
values,
pipe,
map,
split,
last,
keys,
equals
} from 'ramda';
@sdolidze
sdolidze / co.js
Last active August 29, 2015 14:26
import co from 'co'
co(function *() {
try {
yield Promise.reject('sandro');
} catch (e) {
console.log(e);
}
let [a, b] = yield [
$xs = User::where('name', 'leven')
->orderBy('name')
->take(10)
->get();
$ys = User
::where('name', 'leven')
->orderBy('name')
->take(10)
->get();
@sdolidze
sdolidze / Reduce.hs
Created May 17, 2015 03:58
Reduce.hs
import Prelude hiding (takeWhile, dropWhile)
takeWhile :: (a -> Bool) -> [a] -> [a]
takeWhile p xs = snd $ foldl reducer (True, []) xs
where reducer = \(take, xs) x -> if take && p x then (True, xs ++ [x]) else (False, xs)
dropWhile :: (a -> Bool) -> [a] -> [a]
dropWhile p xs = snd $ foldl reducer (True, []) xs
where reducer = \(drop, xs) x -> if drop && p x then (True, xs) else (False, xs ++ [x])
var R = require('ramda');
// in production code, don't forget bounds check.
var removeAtIndex = (n, xs) => R.concat(R.take(n, xs), R.drop(n+1, xs));
console.log(R.eqDeep(['B', 'C'], removeAtIndex(0, ['A', 'B', 'C'])));
console.log(R.eqDeep(['A', 'C'], removeAtIndex(1, ['A', 'B', 'C'])));
console.log(R.eqDeep(['A', 'B'], removeAtIndex(2, ['A', 'B', 'C'])));
@sdolidze
sdolidze / Closure.cs
Last active August 29, 2015 14:16
Closure
using System;
using System.Collections.Generic;
namespace Closure
{
class Closure
{
static List<Action> ClosureIncorrect()
{
var actions = new List<Action>();
@sdolidze
sdolidze / gist:fa7e21a4c5b3d3088611
Created March 4, 2015 19:39
MkhedruliToAsomtravruli
function mkhedruliToAsomtravruli(mkhedruliString) {
return mkhedruliString
.split("")
.map(function(mkhedruliChar) {
return String.fromCharCode(mkhedruliChar.charCodeAt(0) - 48);
})
.join("");
}
mkhedruliToAsomtravruli("სანდრო"); // outputs ႱႠႬႣႰႭ
// ეს კოდი სვიფტში უპრობლემოდ კომპილირდება
typealias რიცხვი = Int
func მიმატება(ა: რიცხვი, ბ: რიცხვი) -> რიცხვი {
return ა + ბ
}
მიმატება(1, 2)
enum List<T> {
case Empty
case Cons(head: T, tail: List<T>)
}
@sdolidze
sdolidze / choose.hs
Created February 7, 2015 00:03
Choose.hs
choose :: [b] -> Int -> [[b]]
_ `choose` 0 = [[]]
[] `choose` _ = []
(x:xs) `choose` k = (x:) `fmap` (xs `choose` (k-1)) ++ xs `choose` k