Skip to content

Instantly share code, notes, and snippets.

Fugroup fugroup

View GitHub Profile
@fugroup
fugroup / class_autobind_utils.js
Last active Jul 4, 2018
Automatically bind all function to itself from constructor of a class
View class_autobind_utils.js
// Usage: inside the constructor of a class do util.autobind(this)
const util = {}
// Binds the object instance functions to itself
util.autobind = (obj) => {
const prototype = Object.getPrototypeOf(obj)
const props = Object.getOwnPropertyNames(prototype)
for (const name of props) {
const value = prototype[name]
@fugroup
fugroup / graph_traversal_javascript_with_update.js
Created Apr 29, 2018
Graph traversal javascript with update convert date
View graph_traversal_javascript_with_update.js
// The object graph
let date = new Date()
let data = {
result: {
id: 'query1',
list: [1, 'hello', date],
hash: {hello: 1, bye: 2, z: 'hello', d: date},
goal: 50,
created_at: date
}
@fugroup
fugroup / traverse_object_graph_javascript.js
Created Apr 29, 2018
Traverse object graph pure vanilla javascript
View traverse_object_graph_javascript.js
const traverse = (obj) => {
for (let k in obj) {
if (obj[k] && typeof obj[k] === 'object') {
traverse(obj[k])
} else {
// Do something with obj[k]
}
}
}
View NodeCryptoEncodeDecode.js
// Nodejs encryption with CTR
const crypto = require('crypto')
class Crypto {
constructor () {
this.algorithm = 'aes192'
this.secret = 'd6F3Efeq'
}
encrypt (text) {
View susana-rethinkdb-connect.rb
# Add rethinkdb to Gemfile
# Add to boot.rb: autoload :RethinkDB, 'rethinkdb'
# Set up RabbitMQ queue as well
# Load database settings
config = (YAML.load_file('./config/database.yml') || {})[App.env]
# Connect database
if config
You can’t perform that action at this time.