Skip to content

Instantly share code, notes, and snippets.

@morrelinko
morrelinko / example.js
Created September 16, 2013 13:51
Welcome to your first Gist! Gists are simple code reminders. Whenever you come across a piece of code you think might be useful later on, save it as a Gist. With GistBox, you can also tag the Gist with a label. This is especially useful for keeping them organized by language, project or purpose. For more info about GistBox, visit: http://www.gi…
// log an object to the browser console
console.log({ text: "foobar" });
@morrelinko
morrelinko / gist:8327101
Last active January 2, 2016 15:59
Takes an array of values from an array (with ability to rename keys and manipulate values)
<?php
/**
* @author Morrison Laju <[email protected]>
*/
class ArrayUtils
{
/**
* Returns a new array created from another
* containing only the keys that we want.
@morrelinko
morrelinko / m2cache.py
Created May 6, 2014 16:25
Copy gradle store of libraries into .m2 local cache
import os
import shutil
gradle_cache_dir = 'C:\\Users\\morrelinko\\.gradle\\caches\\modules-2\\files-2.1'
maven_cache_dir = 'C:\\Users\\morrelinko\\.m2\\repository2'
"""
Build a dictionary of java libraries
"""
packages = {}
@morrelinko
morrelinko / post-receive
Last active August 30, 2016 06:52
Git deploy NodeJS script
#!/usr/bin/env node
var fs = require('fs'),
path = require('path'),
child = require('child_process'),
argf = '',
deployDir = '/home/morrelinko/socialinko';
process.stdin.resume();
@morrelinko
morrelinko / vue-log.js
Created February 28, 2017 10:47
VueJS $log Plugin - Log objects without reactive getters & setters
'use strict'
import _ from 'lodash'
let Log = _.noop
Log.install = function (Vue, options) {
Vue.prototype.$log = function (...args) {
try {
console.log(...args.map(arg => _.isPlainObject(arg) ? JSON.parse(JSON.stringify(arg)) : arg))
createCandidate () {
this.$http.post(.....)
.then(res => {
this.candidateId = res.data.id
this.createTask(.....)
})
.catch(noop)
}
@morrelinko
morrelinko / yield-extension.js
Created November 22, 2017 16:29
Nunjucks 'yield' Extension (One liner block expressions)
'use strict'
class YieldExtension {
get tags () {
return ['yield']
}
parse (parser, nodes, lexer) {
let tag = parser.nextToken()
parser.skipSymbol(tag.value)
@morrelinko
morrelinko / example.js
Last active January 9, 2018 17:46
JavaScript Magic Functions
'use strict'
const magic = require('./magic')
class Request {
constructor(req) {
this.req = req
this.user = 'morrelinko'
}
@morrelinko
morrelinko / magic.js
Created January 9, 2018 17:47
JS Magic Methods
'use strict'
const assert = require('assert')
module.exports = function (obj) {
return new Proxy(obj, {
get (target, prop, receiver) {
if (prop in target) {
return Reflect.get(target, prop, receiver)
}
@morrelinko
morrelinko / compiler.js
Last active June 8, 2022 08:15
Nunjucks Components
'use strict'
const { nodes, runtime } = require('nunjucks')
module.exports = function compileComponent (node, frame) {
let componentId = this._tmpid()
let templateId = this._tmpid()
let templateId2 = this._tmpid()
let componentVar = `component_${componentId}`