Skip to content

Instantly share code, notes, and snippets.

View riston's full-sized avatar

Risto Novik riston

View GitHub Profile
@riston
riston / enc.js
Created June 11, 2016 16:23
Encrypt-decrypt AES256 Node.js with crypto module example
var crypto = require("crypto");
function encrypt(key, data) {
var ciph = crypto.createCipher("aes256", key);
ciph.end(data);
var encBuffer = ciph.read();
// Convert to base64
return encBuffer.toString("base64");
@riston
riston / download-file.js
Created June 6, 2016 13:46
Download file without extra libraries
var http = require("http");
var fs = require("fs");
function getFile(url, saveFile, cb) {
var request = http.get(url, response => {
var write$ = fs.createWriteStream(saveFile);
write$.on("error", cb);
write$.on("finish", () => cb(null));
response.pipe(write$);
@riston
riston / docker-compose.yml
Created May 18, 2016 19:38
Docker compose example current dev env.
mongodata:
image: mongo:3.2.6
volumes:
- /data/mongodb
command: --break-mongo
mongo:
image: mongo:3.2.6
volumes_from:
- mongodata
@riston
riston / command.go
Created February 27, 2016 16:37
Simple command pattern in Go lang
package main
import "fmt"
type Command interface {
Execute() string
}
type PingCommand struct{}
func (p *PingCommand) Execute() string {
@riston
riston / future.go
Last active January 9, 2016 11:27
Go patterns
package main
import (
"fmt"
"time"
)
// Function blocks the execution until the heavy execution is done
func heavySum(a, b int) chan int {
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
#!/bin/sh
scrot /tmp/screenshot.png
convert /tmp/screenshot.png -blur 0x7 /tmp/screenshotblur.png
i3lock -i /tmp/screenshotblur.png
@riston
riston / gen.js
Created October 23, 2015 19:38
Generators execution flow example
"use strict";
const vo = require("vo");
function wait(fn, time) {
time = time || 0;
if (typeof fn === "function") {
fn = fn();
@riston
riston / gulp-check.js
Created October 22, 2015 11:27
Check if there are any packages which need upgrade
gulp.task("package-check", function () {
// Output the packages which needs upgrade
var format = function (upgraded) {
var packages = Object.keys(upgraded);
console.log("Following packages needs to be upgraded:");
packages.forEach(function (packageName)
@riston
riston / average.js
Created September 9, 2015 20:30
Exponential moving average for streams
// Exponential moving average
function average (alpha) {
var last;
alpha = alpha || 3/4;
return function (input) {
if (!last) {
last = input;