Skip to content

Instantly share code, notes, and snippets.

@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}`
@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 / 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 / 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)
createCandidate () {
this.$http.post(.....)
.then(res => {
this.candidateId = res.data.id
this.createTask(.....)
})
.catch(noop)
}
@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))
@morrelinko
morrelinko / app.js
Created October 15, 2016 17:04
Vue Noty Plugin
'use strict'
import Vue from 'vue'
import Notify from './plugins-notify'
Vue.use(Notify)
const app = new Vue({
el: '#app',
mounted () {
@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 / 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 / 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 <morrelinko@gmail.com>
*/
class ArrayUtils
{
/**
* Returns a new array created from another
* containing only the keys that we want.