Skip to content

Instantly share code, notes, and snippets.

Fugroup fugroup

Block or report user

Report or block fugroup

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
View NodeCryptoEncodeDecode.js
// Nodejs encryption with CTR
const crypto = require('crypto')
class Crypto {
constructor () {
this.algorithm = 'aes192'
this.secret = 'd6F3Efeq'
}
encrypt (text) {
@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]
}
}
}
@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 / 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 / get-object-value-from-path.js
Created Nov 26, 2019
Get an object value from path and return undefined if not found
View get-object-value-from-path.js
// Get an object value from path
function getValue(obj, path) {
var keys = path.split('.')
for (var i = 0; i < keys.length; i++) {
try {
obj = obj[keys[i]]
} catch(e) {
return
}
You can’t perform that action at this time.