Skip to content

Instantly share code, notes, and snippets.

View Andrei-Pozolotin's full-sized avatar

Andrei Pozolotin Andrei-Pozolotin

View GitHub Profile
@Andrei-Pozolotin
Andrei-Pozolotin / ubuntu_ami_ids.sh
Created May 11, 2016 17:53 — forked from goura/ubuntu_ami_ids.sh
Get a list of AMI IDs for a specific Ubuntu version
#/bin/sh
curl https://cloud-images.ubuntu.com/locator/ec2/releasesTable | jsonlint -Sf | jq '[.aaData[]|select(.[1]=="trusty" and .[3]=="amd64" and .[4]=="hvm:instance-store")|{region:.[0], ami_id:(.[6]|sub("<a [^<]+>"; "")|sub("</a>"; ""))}]'
@Andrei-Pozolotin
Andrei-Pozolotin / java-signals-test.sh
Created November 21, 2016 18:08 — forked from nicoulaj/java-signals-test.sh
What signals can your JRE handle ?
#!/bin/bash
# Get temp dir
tmpdir=$(mktemp -d)
# Generate test
cat > ${tmpdir}/ListenToSignal.java <<EOF
import sun.misc.Signal;
import sun.misc.SignalHandler;
public class ListenToSignal {

Scoped Implicit Lifetimes

All things considered, our experience in Scala Native has shown that resource management in Scala is way harder than it should be. This gist presents a simple design pattern that makes it resource management absolutely hassle-free: scoped implicit lifetimes.

The main idea behind it is to encode resource lifetimes through a concept of an implicit scope. Scopes are necessary to acquire resources. They are responsible for disposal of the resources once the evaluation exits the

@Andrei-Pozolotin
Andrei-Pozolotin / ExecutionContextExecutorServiceBridge.scala
Created March 15, 2017 17:42 — forked from viktorklang/ExecutionContextExecutorServiceBridge.scala
Turning an ExecutionContext to an ExecutorService (or rather and ExecutorService AND an ExecutionContext) using Scala 2.10+
/*
Copyright 2013 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
@Andrei-Pozolotin
Andrei-Pozolotin / gist:85a1218c2a2353890e4222d6b8eb78db
Created November 21, 2017 23:47 — forked from xeno-by/gist:5967900
Macro-powered structural types
import scala.annotation.StaticAnnotation
import scala.reflect.macros.Macro
import language.experimental.macros
class body(tree: Any) extends StaticAnnotation
trait Macros extends Macro {
import c.universe._
def selFieldImpl = {
@Andrei-Pozolotin
Andrei-Pozolotin / pretty-print.scala
Created January 26, 2018 00:15 — forked from carymrobbins/pretty-print.scala
Pretty print Scala case classes and other data structures.
/**
* Pretty prints a Scala value similar to its source represention.
* Particularly useful for case classes.
* @param a - The value to pretty print.
* @param indentSize - Number of spaces for each indent.
* @param maxElementWidth - Largest element size before wrapping.
* @param depth - Initial depth to pretty print indents.
* @return
*/
private def prettyPrint(a: Any, indentSize: Int = 2, maxElementWidth: Int = 30, depth: Int = 0): String = {
@Andrei-Pozolotin
Andrei-Pozolotin / Atom.scala
Created June 22, 2018 16:50 — forked from kirked/Atom.scala
Clojure atoms, in Scala
/*------------------------------------------------------------------------------
* MIT License
*
* Copyright (c) 2017 Doug Kirk
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@Andrei-Pozolotin
Andrei-Pozolotin / hash_fnv1a.h
Created April 10, 2019 20:01 — forked from ruby0x1/hash_fnv1a.h
FNV1a c++11 constexpr compile time hash functions, 32 and 64 bit
#pragma once
#include <stdint.h>
//fnv1a 32 and 64 bit hash functions
// key is the data to hash, len is the size of the data (or how much of it to hash against)
// code license: public domain or equivalent
// post: https://notes.underscorediscovery.com/constexpr-fnv1a/
inline const uint32_t hash_32_fnv1a(const void* key, const uint32_t len) {
@Andrei-Pozolotin
Andrei-Pozolotin / progress.py
Created May 9, 2019 23:15 — forked from NateEag/progress.py
A way to DRY wxPython progress dialogs for background threads.
#! /usr/bin/env python
"""Tools for running threads behind a wx.ProgressDialog."""
# Standard library imports.
import sys
import threading
import time
# Third party imports.