Skip to content

Instantly share code, notes, and snippets.

View riston's full-sized avatar
🇪🇪

Risto Novik riston

🇪🇪
View GitHub Profile
@riston
riston / remove.js
Last active December 12, 2022 15:21
Remove empty objects from object, recursive
var removeEmpty = function(object) {
if (!_.isObject(object)) {
return;
}
_.keys(object).forEach(function(key) {
var localObj = object[key];
@riston
riston / rps.js
Last active August 29, 2015 14:06
reverse polish stack
var isOp = function (op) {
return !!({
'+': true,
'-': true,
'*': true,
'/': true
}[op])
};
var applyOp = function (op, a, b) {
@riston
riston / array.js
Created August 26, 2014 09:05
Immutable origin array
var a = [1,2,3]
// Using lodash or underscore
var b = _.clone(a);
var c = Array.prototype.slice.call(a, 0);
var d = a.concat()
@riston
riston / cue-flac-splitter.sh
Created May 31, 2014 07:01
Cue flac splitter
#!/bin/bash
# split image file (flac, ape, wav, etc.) according to cue-file
if [ -f "$1" ]; then
i=0
for cuefile in *.cue; do
i=$(($i + 1))
done
if [ $i -eq 1 ]; then
# precies 1 cuesheet gevonden
@riston
riston / dk.sublime-project
Created May 7, 2014 06:42
Sublime project file setup
{
"folders":
[
{
"path": "app-api-new",
"follow_symlinks": true,
"name": "API",
},
{
"path": "app-new-fe",
@riston
riston / publisher.js
Last active August 29, 2015 14:00
RabbitMQ nodejs example message ack
var amqp = require('amqp'),
C = require('config'),
config = C.server,
connection;
connection = amqp.createConnection({
url: config.rabbitmq.url
});
connection.on('ready', function() {
@riston
riston / svg2png.js
Created April 3, 2014 14:25
Convert currently active svg to png, copy this to your web console and execute "svg2png(document.querySelector('svg'))", click the url to open.
// Takes an SVG element as target
function svg2png(target) {
// Flatten CSS styles into the SVG
for (i = 0; i < target.childNodes.length; i++) {
child = target.childNodes[i];
child.style.cssText = window.getComputedStyle(child).cssText;
}
var box = target.viewBox.baseVal;
@riston
riston / client.html
Created March 27, 2014 20:08
Broken websocket mp3 stream implementation
<!DOCTYPE html>
<html>
<head>
<title>Test websocket</title>
</head>
<script type="text/javascript">
var context = new webkitAudioContext();
var ws = new WebSocket("ws://localhost:8080");
var startTime = context.currentTime;
@riston
riston / cb.js
Created March 12, 2014 10:07
Callback handling styles...
db.findById(id, function (err, res) {
if (err) {
return cb(err);
}
// Handle result
return cb(null, _.transform(res));
});
@riston
riston / gist:9151793
Created February 22, 2014 10:35
Highland stream
var _ = require('highland'),
request = require('request');
// This works but not using the stream approach
// function get(path) {
// return _(function (push, next) {
// request(path, function (error, response, body) {
// // The response itself also contains the body