Skip to content

Instantly share code, notes, and snippets.

View the-architect's full-sized avatar
🐒
working on ... 👨🏼‍💻

Marcel Scherf the-architect

🐒
working on ... 👨🏼‍💻
View GitHub Profile
@the-architect
the-architect / repl.js
Last active May 3, 2020 10:18
Mongoose REPL
// load environment variables from .env file
require('dotenv').config();
// load mongoose and connect to db using env variable
const mongoose = require('mongoose');
mongoose.connect(process.env.MONGODB_CONNECTION, { useNewUrlParser: true, useUnifiedTopology: true });
// start the node repl
const repl = require('repl');
const context = repl.start().context;
@the-architect
the-architect / utility.js
Created April 12, 2017 20:16
ES6 Utility Class: Create a new element and attach it to another one
export const Utility = {
createElement: function(tagName = 'DIV', className, appendTo) {
let element = document.createElement(tagName);
element.className = className;
if(typeof appendTo !== 'undefined'){
appendTo.appendChild(element);
}
return element;
}
};
@the-architect
the-architect / pub_sub.js
Created April 12, 2017 20:15
ES6 Simple global PubSub system
export class PubSub {
constructor (){
this.subscriptions = {};
}
subscribe (event, subscriber) {
if (typeof this.subscriptions[event] === 'undefined') {
this.subscriptions[event] = new Set();
}
this.subscriptions[event].add(subscriber);
@the-architect
the-architect / tab_control.js
Created April 12, 2017 20:13
ES6 Simple Tab Control
export class TabControl {
constructor(element){
this.element = element;
this.element.addEventListener('click', this.handleClick.bind(this));
let firstOption = this.element.querySelector('.tab-option');
firstOption.classList.add('active');
}
handleClick(e){
class ActiveRecord::Base
def self.import!(record_list)
raise ArgumentError 'record_list not an Array of Hashes' unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash }
return if record_list.empty?
record_list.in_groups_of(1000, false).each do |record_group|
key_list, value_list = convert_record_list(record_group)
sql = "INSERT INTO #{self.table_name} (#{key_list.join(', ')}) VALUES #{value_list.map {|rec| "(#{rec.join(', ')})" }.join(' ,')}"
self.connection.insert_sql(sql)
@the-architect
the-architect / .rsyncignore
Created July 18, 2014 17:50
configure vagrant-rsync exclude with an .rsyncignore file
log/*.log
tmp/**/*
tmp/*
# IntelliJ
*.iml
.idea
# SASS
@the-architect
the-architect / gist:d0ea1b6eb25a5a328c3b
Created July 16, 2014 02:45
tail file even if it does not exist yet, becomes inaccessible or gets replaced
# use the capital F flag:
# -F => same as -f --retry
# --retry keep trying to open a file even if it is inaccessible when tail starts or if it becomes inaccessible later
tail -F filename
@the-architect
the-architect / gist:d69d0c0e13646efa50be
Created July 9, 2014 23:49
Find out Ubuntu version
lsb_release -a
@the-architect
the-architect / cmdstamp.sh
Last active August 29, 2015 14:03
Show the last accessed timestamp for a command line program in path
# ubuntu:
# add this to your ~/.bashrc
cmdstamp(){
which $1 | xargs stat -c '%Y'
}
@the-architect
the-architect / html5_placeholder_styling.scss
Created June 21, 2014 10:06
Style HTML5 placeholder text
body{
// unfortunately we need to enter each of these browser specific selectors
::-webkit-input-placeholder { font-style:italic; }
:-moz-placeholder { font-style:italic; }
::-moz-placeholder { font-style:italic; }
:-ms-input-placeholder { font-style:italic; }
}