Skip to content

Instantly share code, notes, and snippets.

@arkadijs
arkadijs / Main.java
Created December 16, 2016 12:06
Dekker's algorithm
package dekker;
public class Main {
private static volatile boolean flag0 = false;
private static volatile boolean flag1 = false;
private static volatile int turn = 0;
private static long count = 0;
private static long count0 = 0;
private static long count1 = 0;
@arkadijs
arkadijs / channels.rs
Created September 10, 2016 15:43
Beauty of Rust
use std::char;
use std::collections::HashMap;
use std::thread;
use std::sync::{Arc, Barrier};
use std::sync::mpsc::{channel, Sender};
const NTHREADS: u32 = 5;
fn slow(n: u32) -> char {
thread::sleep_ms(n);
import (
"archive/zip"
"fmt"
awss3 "github.com/aws/aws-sdk-go/service/s3"
"io"
)
var s3 *awss3.S3
head, err := s3.HeadObject(
@arkadijs
arkadijs / catc.sh
Last active March 1, 2016 21:41
Cat's C Xcode template
#!/bin/sh -xe
cd $HOME/Library/Developer/Xcode
tmpl='Templates/File Templates/Source'
catc=$tmpl/'Cat C File.xctemplate'
mkdir -p "$tmpl"
cp -pr '/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source/C File.xctemplate' "$catc"
find "$catc" -name '*.[ch]' -print0 |
xargs -0 sed -i '' -e 's@___COPYRIGHT___@ != == > <\
// \&\& ||@g'
@arkadijs
arkadijs / Week1.md
Last active January 4, 2016 09:39
Groovy Grails life

The Origin

I'm here not to teach you - see me as a guiding friend, a facilitator. We'll go together through a journey of getting better at some particular, non-hype, well understood yet sometimes problematic, still modern technology for developing web- and service-oriented applications. Hopefully it will give you a new perspective on how such things could be built.

It's up to you to choose what it'll be for you - an epic or a walk in the park. Most of the value will be to stay till the end, though.

To do the homework I expect about 5 hours of commitment per week -- similar to [Coursera]. Some colleagues already demonstrated that it could be done. But, compared to consuming nicely prepared material, we're on raw side this time -- you'll be setting your own tactical learning plan and digging for materials instead.

Last but not least, my opinion and judgments are always subjective.

@arkadijs
arkadijs / gameoflife1.py
Created December 24, 2013 22:52
Coderetreat: Java 8 vs Scala http://ldn.lv/events/138303652/ (Python quietly sneaks in)
import time
def cell_transition(alive, neighbour_count):
return neighbour_count in (2, 3) if alive else neighbour_count == 3
class RectField(object):
def __init__(self, size, cells):
self.size = size
@arkadijs
arkadijs / README.md
Last active December 17, 2015 00:09
Homework for LDN event Workshop: Clojure http://ldn.lv/events/113852292/

Immutant primer

Homework for LDN event [Workshop: Clojure][event].

Task

Follow [Immutant Tutorials][tutorials] and install [Leiningen][leiningen] and [Immutant][install].

  1. Create [web handler][deploy] for /?counter=some-name
  2. Create [queue][messaging] to enqueue some-name
  3. Create [cache][caching]
  4. Read from queue and increment cache(some-name)
@arkadijs
arkadijs / cron.scala
Last active December 10, 2015 12:48
TreSQL usage examples
transactional {
val delta = event.days // 7 days
val q =
"""
|construction_merchants [status = :active] {id}
|-
| construction_merchants merchant
|[merchant.prn_id = official_list.prn_id] official_list
|[official_list.child_id = member.prn_id] construction_merchants member
|[merchant.status = :active & member.status = :active & official_list.date_to = null & official_list.typ = :org]
import Test.Hspec
import Data.List
anagrams :: [String] -> String -> [String]
anagrams lwords checkword = filter (wordsAreAnagrams checkword) lwords
wordsAreAnagrams :: String -> String -> Bool
wordsAreAnagrams a b = (a /= b) && (sort a == sort b)
allAnagrams :: [String] -> [[String]]