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 / install_python3.6_opensuse42.3.sh
Last active December 12, 2022 08:26
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.
@amoilanen
amoilanen / remove_ubuntu_repos_from_apt.sh
Created October 21, 2016 17:38
Cleans up accidentally added ubuntu repos from the apt sources list in Debian
#Cleans up accidentally added Ubuntu repositories from the Debian's repository list
#!/bin/bash
sourcesDir=/etc/apt/sources.list.d
fileNames=$(ls $sourcesDir)
for fileName in $fileNames
do
fullFilePath=$sourcesDir/$fileName
fileSourcesList=$(cat $fullFilePath)
if [[ "$fileSourcesList" =~ "ubuntu" ]]
then
@amoilanen
amoilanen / mandelbrot.set.html
Last active October 13, 2016 20:42
Mandelbrot set visualization using the escape algorithm
<!-- Hosted https://output.jsbin.com/gowiruwiku/2 -->
<html>
<header>
<style type="text/css">
body {
margin: 0;
padding: 0;
background-color: black;
}