Skip to content

Instantly share code, notes, and snippets.

View amoilanen's full-sized avatar
💭
"Simplicity is prerequisite for reliability." Edsger W. Dijkstra

Anton Moilanen amoilanen

💭
"Simplicity is prerequisite for reliability." Edsger W. Dijkstra
View GitHub Profile
@amoilanen
amoilanen / create_bootable_drive.sh
Created September 24, 2018 09:28
Command to create bootable USB with progress displayed using dd, pv
sudo dd if=./some.linux.iso | pv -s 2G | sudo dd of=/dev/sdb bs=8192
@amoilanen
amoilanen / akka_stream_example.scala
Created March 11, 2018 22:25
Simple example of a stream in Akka: source -> flow -> sink
import akka.actor.ActorSystem
import akka.stream.scaladsl._
import akka.stream._
object AkkaStreamExample extends App {
implicit val system = ActorSystem("MyActorSystem")
implicit val materializer = ActorMaterializer()
val source = Source(1 to 5)
val square = Flow[Int].map(x => x * x)
@amoilanen
amoilanen / install_python3.6_opensuse42.3.sh
Last active March 25, 2025 21:16
Installing Python 3.6 on OpenSUSE Leap 42.3
# !/bin/bash
# Step 1. Install pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
source ~/.bashrc
@amoilanen
amoilanen / terminate.sh
Last active August 19, 2018 15:01
Better 'killall' command in Bash, analogous to 'kill -9' usage: 'terminate.sh java'
#!/bin/bash
pids_to_kill=$(ps aux|grep $1|grep -v grep|grep -v terminate.sh |awk '{print $2}')
[[ ! -z $pids_to_kill ]] && kill -9 $pids_to_kill
@amoilanen
amoilanen / bash_find_large_directories.sh
Last active August 15, 2018 12:55
Bash command that finds subdirectories of the current directory that are larger than 1Gb
du -h | grep '^[0-9]\.*[0-9]*G'
@amoilanen
amoilanen / browser_text_mode.js
Created May 17, 2017 15:27
Remove images, videos and backgrounds from the web page to leave only the text content
(function() {
function toArray(arrayLike) {
return [].slice.call(arrayLike);
}
function $(cssSelector) {
return toArray(document.querySelectorAll(cssSelector));
}
@amoilanen
amoilanen / generator_demo.js
Created April 4, 2017 14:13
Simple demo of generators in JavaScript
function print(obj) {
console.log(JSON.stringify(obj, null));
}
function* gen() {
var x = yield 'a';
var y = yield 'b';
var z = yield 'c';
return [x, y, z];
@amoilanen
amoilanen / list.all.months.js
Created March 23, 2017 14:41
Lists all months names in the en-US locale in pure JavaScript (ES6)
function listMonths() {
var currentDate = new Date();
return Array.from(new Array(12), (_, monthIdx) => {
currentDate.setMonth(monthIdx);
return currentDate.toLocaleString("en-US", {month: "long"})
});
}
console.log(listMonths());
var spawn = require('child_process').spawn;
var sh = spawn('sh');
sh.stdout.on('data', function (data) {
console.log('sh: \n', data.toString());
});
sh.stderr.on('data', function (data) {
console.error('error: \n', data.toString());
@amoilanen
amoilanen / clock_example.elm
Created December 29, 2016 20:48
Demonstrates Elm architecture: models, commands, subscriptions, modified version of the tutorial example
{-
Copyright (c) 2014-2016, Evan Czaplicki
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.