Skip to content

Instantly share code, notes, and snippets.

@arkadijs
arkadijs / patmat.rs
Created June 27, 2015 16:07
Beauty of Rust
#![feature(convert, slice_patterns)]
#![allow(unused_variables)]
// http://pzol.github.io/getting_rusty/posts/20140417_destructuring_in_rust/
use std::env;
use std::io::BufReader;
use std::io::BufRead;
use std::fs::File;
@arkadijs
arkadijs / lifetimes.rs
Last active August 29, 2015 14:23
Beauty of Rust
#![allow(dead_code, unused_variables)]
#[derive(Debug)]
struct Node<'l, 'r> {
val: u32,
left: Option<&'l Node<'l, 'l>>,
right: Option<&'r Node<'r, 'r>>
}
impl<'l, 'r> Node<'l, 'r> {
@arkadijs
arkadijs / MasterOfNames.scala
Created May 15, 2015 15:50
Give meaningful names, improve code, write some tests.
def a(b: List[AnyRef]): List[String] =
b.foldLeft(List[String]())((c, d) => d match {
case null => c
case e: String => c :+ e
case f: List[AnyRef] => c ++ a(f)
})
def g(h: List[String]) =
h.foldLeft(List[String]())((i, j) => i.lastOption match {
case Some(`j`) => i
@arkadijs
arkadijs / reactive.md
Last active August 29, 2015 14:18
Reactive programming workshop http://ldn.lv/events/220739388

Reactive workshop

Today we're building Instagram image scraper.

Instagram has an API to poll for recent media to get media's attributes, including URL and location. Your program will be sending that information to a pre-cooked web UI for display.

Step zero: Necessary evil

Please login into Instagram, go to https://instagram.com/developer/ and create an app (Manage Client > Register a New Client) to obtain Client ID that is required to call Instagram's API. You may put http://rxdisplay.neueda.lv/ into Website and http://rxdisplay.neueda.lv/oauth into OAuth redirect uri. Any other URL-s would do too.

@arkadijs
arkadijs / cloud-ide.md
Last active December 16, 2016 12:38
Cloud IDE mini-review
  1. Koding - Attach your own VM. Nice UI. Has Chrome app.
  2. Cloud9 - 512MB free tier memory limit. Scala and Groovy processes will be killed pretty soon due to OOM.
  3. Codenvy - Docker runners automagic fail (cannot run arbitrary startup command). Can show Javadoc.
  4. Nitrous - defunct.
  5. Codebox - defunct.
@arkadijs
arkadijs / instagram.groovy
Last active August 29, 2015 14:18
Instagram Tags media feed based on Observable / ReactiveX in Scala, Groovy, and Java. https://bitbucket.org/arkadi/instarx
@Grapes([
@Grab('io.reactivex:rxgroovy:1.0.0'),
@Grab('org.codehaus.gpars:gpars:1.2.1'),
@Grab('com.github.groovy-wslite:groovy-wslite:1.1.0')])
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import rx.Observable
import rx.Subscriber
import rx.schedulers.Schedulers
@arkadijs
arkadijs / instagram.groovy
Last active August 29, 2015 14:18
Instagram real-time Tags and Geographies subscription via Groovy and Ratpack https://instagram.com/developer/realtime/
@Grapes([
@Grab('org.codehaus.gpars:gpars:1.2.1'),
@Grab('com.github.groovy-wslite:groovy-wslite:1.1.0'),
@Grab('io.ratpack:ratpack-groovy:0.9.15'),
//@Grab('io.ratpack:ratpack-jackson:0.9.15'),
@Grab('org.slf4j:slf4j-simple:1.7.12')])
import static groovyx.gpars.actor.Actors.actor
import static ratpack.groovy.Groovy.ratpack
import ratpack.http.client.HttpClient
@arkadijs
arkadijs / stack.txt
Created March 19, 2015 16:59
export RUST_BACKTRACE=1
thread '<main>' panicked at 'index out of bounds: the len is 1339 but the index is 1339', /build/buildd/rust-nightly-201503180407~1ae32de~trusty/src/libcollections/vec.rs:1336
stack backtrace:
1: 0x7feb92fed9d4 - sys::backtrace::write::h781dfe74347a79cb10C
2: 0x7feb92ff15df - panicking::on_panic::hafa4f854a38dccfathJ
3: 0x7feb92fe248a - rt::unwind::begin_unwind_inner::hea0351e9a595ba7f2XI
4: 0x7feb92fe2b41 - rt::unwind::begin_unwind_fmt::he1aaa061d26e63b9DWI
5: 0x7feb92ff0fc7 - rust_begin_unwind
6: 0x7feb9301cb94 - panicking::panic_fmt::h6d00c31e190682d1Tku
7: 0x7feb9301defc - panicking::panic_bounds_check::hf4aded192863f504Zju
8: 0x7feb92f07536 - vec::Vec<T>.Index<usize>::index::h1583112471073907091
@arkadijs
arkadijs / _README.md
Last active October 16, 2018 19:02
Registrator / SkyDNS for CoreOS / Deis cluster

Registrator and SkyDNS

We use progrium/registrator and yaronr/skydns (SkyDNS2) to publish information about Docker containers to DNS via A and SRV records. All nodes runs skydns and registrator, and first three nodes are inserted as NS-s into Route53 DNS for services.cluster-name.domain.io. Note, v4 registrator must be used until registrator/124 is resolved.

$ host -t srv mysql-1.services.deis.r53.acp.io deis-6-1.eu.r53.acp.io
Using domain server:
Name: deis-6-1.eu.r53.acp.io
Address: 54.171.239.227#53
Aliases: 
@arkadijs
arkadijs / fabfile.py
Last active August 29, 2015 14:16
Fabric full cycle Groovy app deployment with process restart, pid file, apt, cron, tmux, credentials templating, groovy install.
import os
from fabric.api import *
from fabric.operations import run, sudo, get, put
from fabtools import require
from time import sleep
from ConfigParser import RawConfigParser
from StringIO import StringIO
# if passwordless sudo is required, please add
# /etc/sudoers.d/01-cloudf