Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Karma Blackshaw KarmaBlackshaw

🎯
Focusing
View GitHub Profile
View knex-helper.js
const _flatten = require('lodash/flatten')
const _isEmpty = require('lodash/isEmpty')
const isObject = obj => Object.prototype.toString.call(obj) === '[object Object]'
const getKey = (key, obj) => obj[key] === undefined ? obj.default : obj[key]
module.exports = knex => {
const knexHelper = {
raw: qb => knex.raw(qb),
jsonObject ({ alias, data }) {
View default-node-eslint.js
module.exports = {
env: {
browser: true,
commonjs: true,
es6: true,
node: true,
},
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
View light-render-replace.js
var data = {
firstName: 'Mike',
lastName: 'Tyson'
}
var template = 'Hello my name is {{firstName}} {{lastName}}'
function render (template, data) {
return template.replace(/{{(.+?)}}/g, (m, p1) => data[p1])
}
@KarmaBlackshaw
KarmaBlackshaw / mysql.md
Last active Mar 9, 2021
List of MySQL Basic Use Cases
View mysql.md

List of MySQL Basic Use Cases

BULK UPDATE

When updating multiple rows with different values it is much quicker to use a bulk update.

UPDATE people 
SET name = 
  (CASE 
    WHEN id = 1 THEN 'Karl'
View 10001st-prime.md

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

const isPrime = num => {
  const sqrt = Math.sqrt(num)
  for (let i = 2; i <= sqrt; i++) {
    if (num % i === 0) {
      return false
@KarmaBlackshaw
KarmaBlackshaw / socket-wilcard.md
Last active Jan 4, 2021
Listen for every custom events in a socket
View socket-wilcard.md

Socket IO Wildcard Listener

Listen for every custom events in a socket

Installation

const onevent = socket.onevent;
socket.onevent = function (packet) {
  const args = packet.data || [];
  onevent.call (this, packet);    // original call
@KarmaBlackshaw
KarmaBlackshaw / colorize.md
Last active Jun 20, 2020
Colorize your terminal output in Node.js
View colorize.md

Console Colorizer

Put colors to your console.logs

Usage

Create a file and paste the following

@KarmaBlackshaw
KarmaBlackshaw / closure.js
Created Jun 20, 2020
Basic Example of Closure
View closure.js
function sandwichMaker(magicIngredient) {
function make(filling) {
return magicIngredient + " and " + filling;
}
return make;
}
const hamAnd = sandwichMaker("ham");
hamAnd("cheese"); // "ham and cheese"
@KarmaBlackshaw
KarmaBlackshaw / VueLocalStorage.js
Last active Jun 18, 2020
Local Storage wrapper for concatenating local storage items with your preferred name
View VueLocalStorage.js
const memoize = (fn) => {
const cache = Object.create(null)
return function cachedFn(...str) {
const key = str.toString()
const hit = cache[key]
return hit || (cache[key] = fn(key))
}
}
const isDef = memoize(v => v !== undefined && v !== null)
View Effective_Engineer.md

FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?