Skip to content

Instantly share code, notes, and snippets.

View riston's full-sized avatar
🇪🇪

Risto Novik riston

🇪🇪
View GitHub Profile
@riston
riston / gist:6269186
Last active December 21, 2015 07:09
Callback with mutable error message.
var fs = require('fs');
var errorHandler = function(err, result) {
return function(customMessage) {
if (err) return err;
else {
// Call some other sync function but with my message
console.log(customMessage);
handleResult(result);
}
@riston
riston / index.html
Created October 21, 2013 19:53
Backbone.js simple CRUD without the backend
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Your first Backbone.js App | Tutorialzine </title>
<!-- Google web fonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Sans:400,700" rel='stylesheet' />
</head>
@riston
riston / cache.js
Last active December 26, 2015 14:48
Is cache file fresh or not.
var fs = require('fs');
var Cache = {
isFresh: function (file, time, cb) {
fs.exists(file, function (exists) {
if (!exists) {
return cb(null, false);
}
@riston
riston / namespace-access.js
Last active January 1, 2016 12:39
Access the Javascript objects with namespace style 'person.name' ...
'use strict';
var expect = require('expect.js');
function get(object, namespace) {
var keys = namespace.split('.'),
currentObj = object,
current;
while (current = keys.shift()) {
var MongoClient = require('mongodb').MongoClient,
config = require('easy-config');
var DB = function () {
function connect (cb) {
MongoClient.connect(config.mongodb.url, function (err, db) {
if (err) {
@riston
riston / befunge.js
Created December 31, 2013 19:13
Befunge code
var Befunge = function () {
var WIDTH = 80,
HEIGHT = 25,
x = 0,
y = 0,
output = [], // This is array for storing output
stack = [],
@riston
riston / IO.vb
Created January 2, 2014 08:39
Visual Basic, reading all text to string from file and writing
Imports
Imports System.IO
Imports System.Text
Public Class MainForm
Private filePath = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\settings.txt"
Private Sub Chart1_Click(sender As Object, e As EventArgs)
@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) {