Skip to content

Instantly share code, notes, and snippets.

View Azerothian's full-sized avatar
♾️
Over thinking, over analyzing separates the body from the mind

Matthew Mckenzie Azerothian

♾️
Over thinking, over analyzing separates the body from the mind
View GitHub Profile
@Azerothian
Azerothian / launcher.coffee
Last active September 14, 2015 07:55
Expects target file to export a Promise. use stdin and stdout for comms between new instance of node
log = require("./logger")("mrc:launcher:")
if require.main == module
file = process.argv[2]
console.log "start", file
target = require file
process.on "message", (args) ->
sendResponse = (status, data) ->
process.send { status, data }
process.exit(0)
return target.apply(undefined, args).then (result) ->
debug = require "debug"
debug.enable('mrc:*')
module.exports = (prefix="", suffix=":") ->
return {
log: debug "#{prefix}log#{suffix}"
debug: debug "#{prefix}debug#{suffix}"
sql: debug "#{prefix}debug:sql#{suffix}"
info: debug "#{prefix}info#{suffix}"
error: debug "#{prefix}error#{suffix}"
@Azerothian
Azerothian / duplicates.sql
Created September 16, 2015 01:58
How to delete rows that are duplicates over a set of columns, keeping only the one with the lowest ID.
DELETE FROM tablename
WHERE id IN (SELECT id
FROM (SELECT id,
ROW_NUMBER() OVER (partition BY column1, column2, column3 ORDER BY id) AS rnum
FROM tablename) t
WHERE t.rnum > 1);
#!/usr/bin/env sh
TEMPLATE_FILE=$1
ENV_PREFIX=$2
env | grep "^$ENV_PREFIX" | while IFS="=" read -r name value; do
printf "s/%s/%q/\n" "${name}" "$value"
done > sed-script.txt
cat sed-script.txt # Optional
sed -f sed-script.txt "$TEMPLATE_FILE"
@Azerothian
Azerothian / jsobjtogql.js
Last active May 1, 2022 04:27
Convert JS Objects to GraphQL Queries
// Babel 2015 - ES6
// Convert a complex JS Object to GraphQL Query, should handle most use cases as of 21/01/2016
const o = {
query: {
fields: {
complex: {
aliasFor: "Products",
processArgs: {
coupon: (value) => {
return `"${JSON.stringify(value).replace(/"/g, "\\\"")}"`; // passing json string as a argument
function demo(nmdb) {
return {
lol: () => {
return nmdb.get("blah");
}
}
}
demo(nmdb).lol().then(() => {
console.log("done");
function rejectOn4(v) {
if (v === 4) {
throw "crash";
}
}
function increment(v){
return v++;
}
<scripts_config.xml checkPing="true" debugInfo="true">
<space>spaces/ocean</space>
<offlineModel>PASD010_Fletcher_1942</offlineModel>
<player entityType="Avatar" startDirection="1.0 0.0 0.0" startPosition="0.0 0.0 -313.0"/>
<cursorScaleSpeed x="40" y="40"/>
<server online="true">
<host addr="login.worldofwarships.jp:20020" alias="WOWS ASIA"/>
<host addr="login.worldofwarships.com:20020" alias="WOWS NA"/>
</server>
<chat visibleLines="6"/>
#!/bin/bash
if [ "$1" != "" ] && [ "$1" = "-h" ]; then
echo "Shipyard Deploy uses the following environment variables:"
echo " ACTION: this is the action to use (deploy, upgrade, node, remove)"
echo " DISCOVERY: discovery system used by Swarm (only if using 'node' action)"
echo " IMAGE: this overrides the default Shipyard image"
echo " PREFIX: prefix for container names"
echo " SHIPYARD_ARGS: these are passed to the Shipyard controller container as controller args"
echo " TLS_CERT_PATH: path to certs to enable TLS for Shipyard"
@Azerothian
Azerothian / jqpromises.js
Created February 23, 2016 01:35
Even in the world of jQuery... promises rain supreme.. even if its a bastardized.
$(".feature-tab-header").on("click", function() {
var targetTab = "." + $(this).attr("id");
var targetHeader = this;
var promises = [
$(".feature-tab.active").removeClass("active").promise(),
$(".feature-tab-header").removeClass("active").promise()
];
return $.when(promises).done(function() {
$(targetHeader).addClass("active");
$(targetTab).addClass("active");