Skip to content

Instantly share code, notes, and snippets.

View riston's full-sized avatar

Risto Novik riston

View GitHub Profile
@riston
riston / promise.js
Created February 15, 2014 18:06
Split files lines into array
var Q = require('q'),
fs = require('fs');
Q.longStackSupport = true;
var filterLargeFilename = function (array) {
var length = 10;
return array.filter(function (name) {
return (name.length <= length);
@riston
riston / find-hash.js
Created February 16, 2014 20:21
Hash finder for hash challange http://www.h11e.com/
var crypto = require('crypto'),
cuid = require('cuid'),
string,
zeros = 0,
currentHash = '',
currentZeros = 0,
hash;
function findZeros(hash) {
var chars = hash.split(''),
@riston
riston / chiper.js
Last active August 29, 2015 13:56
VigenèreCipher
function VigenèreCipher(key, abc) {
var keyLen = key.length,
abcLen = abc.length - 1,
abcObj,
abcToObject;
key = key.split('');
abc = abc.split('');
abcToObject = function (abc) {
@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
@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 / 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 / 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 / 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 / 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 / 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()