Skip to content

Instantly share code, notes, and snippets.

View techfort's full-sized avatar

Joe Minichino techfort

View GitHub Profile
@techfort
techfort / janitor.go
Last active July 16, 2019 10:14
A go program that deletes Redis keys that have not been read for a time greater than a threshold provided and matching a certain pattern
import (
"fmt"
"time"
"github.com/go-redis/redis"
)
type janitor struct {
*redis.Client
}
const add = (a, b) => (a + b);
const cachingFunc = (cacheObj = {}) => {
const cache = cacheObj;
return (a, b) => {
let hash = `${a}:${b}`;
if (!cache[hash]) {
console.log('Computing result');
cache[hash] = add(a, b);
@techfort
techfort / node-example.js
Created June 4, 2015 20:01
nodeExample
var loki = require('lokijs');
var db = new loki('demo.json'),
users = db.addCollection('users');
users.insert({ name: 'joe', age: 40 });
users.insert({ name: 'jack', age: 32});
var result = users.find({ $age: { $gt: 35 }});
angular.module('myapp')
.service('LocalDatabase', ['$rootScope', '$window', 'LOCAL_DB', function ($rootScope, $window, LOCAL_DB) {
var filesystem, db = new loki('mydb'), user, users, coupons;
$window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, obtainedFS, fail);
function obtainedFS(fs) {
filesystem = fs;
loadDatabase();
}
@techfort
techfort / electroloki
Created May 1, 2015 12:38
basic loading of LokiJS in an electron app
var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
var loki = require('lokijs'),
db = new loki(),
users = db.addCollection('users', {
indices: ['username']
});
users.insert({ username: 'joe', age: 40});
users.insert({ username: 'jack', age: 30});
@techfort
techfort / loki2rethink.js
Created April 12, 2015 06:18
Loki2RethinkDB
var rdb = require('rethinkdb'),
loki = require('lokijs'),
db,
connection;
function forwardInsert(db, connection, table, record, callback) {
var cb = callback || function (err, obj) {
if (err) {
throw err;
}
var Collection = require('lokijs').Collection;
var obj = JSON.parse('serializedCollection.js'),
coll = new Collection('myColl');
Object.keys(obj).forEach(function (prop) {
coll[prop] = obj[prop];
});
@techfort
techfort / dynamicviewexample.js
Created November 11, 2014 21:12
LokiJS DynamicView simple example
var loki = require('lokijs'),
db = new loki('test.json'),
doctors = db.addCollection('doctors');
var Log = console.log;
doctors.insert({
name: 'David Tennant',
doctorNumber: 10
});
@techfort
techfort / LokiSaveReload.js
Last active February 5, 2024 10:27
LokiJS - save to disk and reload
var loki = require('lokijs'),
db = new loki('test.json'),
db2 = new loki('test.json');
var users = db.addCollection('users');
users.insert({
name: 'joe'
});
users.insert({
name: 'john'