Skip to content

Instantly share code, notes, and snippets.

View groz's full-sized avatar

Tagir Magomedov groz

  • Amsterdam, NL
  • 21:39 (UTC +02:00)
View GitHub Profile
/*"""
Given a string s and a list of words w, determine if s can be split into a space-separated sequence of one or more words in w.
For example, given
s = "catdog"
w = ["dog", "car", "catch", "cat", "tiger", "at"]
==> True
s = "catdogtail"
w = ["dog", "car", "catch", "cat", "tiger", "at"]
// $ SBT_OPTS="-Xmx12G" sbt run
object MainApp extends App {
def async[R](f: => R): Thread = new Thread {
override def run(): Unit = f
}
def parallel[A, B](f: => A, g: => B): (A, B) = {
var x: Option[A] = None
@groz
groz / deep_get.py
Last active January 10, 2022 13:17
Python deep_get
# coding=utf-8
from __future__ import unicode_literals
import collections
_default_stub = object()
def to_unicode(s):
if isinstance(s, str):
return unicode(s, 'utf8')
@groz
groz / debounce_afisha.js
Last active August 28, 2016 19:13
Debounce afisha daily
// this is the lag source (decompiled code)
addEventScroll: function(e, t) {
var n = this;
e.attachEvent ? e.attachEvent("onscroll", function() {
t.call(n)
}) : e.addEventListener("scroll", function() {
t.call(n)
})
},
@groz
groz / count-change.csm
Created September 4, 2016 16:41
count change in mit-scheme
(define (count-change coins amount)
(display coins) (newline)
(display amount) (newline)
(cond
((= 0 amount) 1)
((< amount 0) 0)
((null? coins) 0)
(else
(+
(count-change coins (- amount (car coins)))
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder b a) 0))
@groz
groz / parse_qs.py
Last active September 30, 2016 11:07
Url encoded query string parser
#!/usr/bin/env python
"""
Parses application/x-www-form-urlencoded string into a json.
Usage example:
~$ echo "a=1&b=2&a=3" | ./parse_qs.py | jq .
{
"a": [
"1",
"3"
//: Playground - noun: a place where people can play
import UIKit
struct Person {
let name: Optional<String>
let age: Optional<Int>
}
let tagir: Person = Person(name: "Tagir", age: 32)
@groz
groz / luhn.elm
Last active November 15, 2016 22:03
Luhn algorithm for credit card validation in Elm
import Html exposing (..)
import Html.Events exposing (..)
import Html.Attributes exposing (..)
-- UI part
main =
beginnerProgram { model = { creditCardNumber = "", isValid = False } , view = view, update = update }
@groz
groz / demo.elm
Created December 15, 2016 12:16
Lunch and learn demo on Elm
module Demo exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main =
Html.beginnerProgram
{ model = model