Skip to content

Instantly share code, notes, and snippets.

View jamesmoey's full-sized avatar

James Moey jamesmoey

  • Sydney Australia
View GitHub Profile
@jamesmoey
jamesmoey / Doctrine.xml
Last active March 6, 2019 23:20
Setter & Getter, Adder & Remover live template for Doctrine Collection. Use in IntellJ
<templateSet group="Custom">
<template name="sgcollection" value="/**&#10; * @return $CLASS$&#10; */&#10;public function get$CLASS$(): $CLASS$&#10;{&#10; return $this-&gt;$VAR$;&#10;}&#10;&#10;/**&#10; * @param $CLASS$ $$$VAR$&#10; * @return $this&#10; */&#10;public function set$CLASS$($CLASS$ $$$VAR$)&#10;{&#10; if ($$$VAR$ !== $this-&gt;$VAR$) {&#10; if ($this-&gt;$VAR$ !== null) {&#10; $this-&gt;$VAR$-&gt;remove$RELATECLASS$($this);&#10; }&#10; $this-&gt;$VAR$ = $$$VAR$;&#10; if ($this-&gt;$VAR$ !== null) {&#10; $this-&gt;$VAR$-&gt;add$RELATECLASS$($this);&#10; }&#10; }&#10; return $this;&#10;}" description="Generate Setter &amp; Getter for Relationship" toReformat="true" toShortenFQNames="true">
<variable name="CLASS" expression="classNameComplete()" defaultValue="" alwaysStopAt="true" />
<variable name="VAR" expression="phpVar" defaultValue="" alwaysStopAt="true" />
<variable name="RELATECLASS" expression="classNameComplet
@jamesmoey
jamesmoey / dnsrecordcreation.sh
Last active January 23, 2018 00:02
Create DNS Record On Google Cloud Compute Engine
#!/bin/sh
IP=$(curl http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip -H "Metadata-Flavor: Google")
gcloud dns record-sets transaction start -z=$1
gcloud dns record-sets transaction remove -z=$1 --name=$2 --type=A --ttl=3600
gcloud dns record-sets transaction add -z=$1 --name=$2 --type=A --ttl=3600 $IP
gcloud dns record-sets transaction execute -z=$1
@jamesmoey
jamesmoey / makeMapJsonSafe.go
Last active November 28, 2016 01:18
Go - Convert unsafe map interface into JSON safe
import (
"strconv"
"reflect"
)
func makeMapJsonSafe(unsafe interface{}) (interface{}) {
if unsafe != nil && reflect.TypeOf(unsafe).Kind() == reflect.Map {
if isArray(unsafe.(map[interface{}]interface{})) {
var jsonSafe = make([]interface{}, len(unsafe.(map[interface{}]interface{})))
for key, value := range unsafe.(map[interface{}]interface{}) {

Keybase proof

                                                                                                                                                                                          I hereby claim:                                                                                                                                                                                                                              
  • I am jamesmoey on github.
  • I am jamesmoey (https://keybase.io/jamesmoey) on keybase.
  • I have a public key ASDeQcViwyv4oVi7sEMxoPhpXzbY6NY2DmEpPSMKq1IbQgo

To claim this, I am signing this object:

{                           
@jamesmoey
jamesmoey / rabbitjs.ts
Created March 22, 2016 20:35
Rabbit.js as RxJS Observable in Typescript
/// <reference path="../typings/tsd.d.ts" />
/// <reference path="../node_modules/rx/ts/rx.all.d.ts" />
import * as Rx from 'rx';
import * as rabbit from 'rabbit.js';
export module Messaging {
export enum PubSocketType {
PUBLISH = <any>'PUB',
@jamesmoey
jamesmoey / dedup-sqs.sh
Created June 26, 2015 01:46
De duplicate message in AWS SQS
declare -A messages;
for i in {1..10000};
do
msg=$(aws --region ap-southeast-2 sqs receive-message \
--queue-url $1 \
--max-number-of-messages 1);
msgMd5=$(echo $msg | jq -r '.Messages[].MD5OfBody');
msgId=$(echo $msg | jq -r '.Messages[].MessageId');
if [ -n "${messages[$msgMd5]}" -a "${messages[$msgMd5]}" != "$msgId" ];
then
@jamesmoey
jamesmoey / Docker UI
Last active September 30, 2015 22:35
Systemd Setup for Etcd + SkyDns + Registrator
[Unit]
Description=Docker UI Service
Documentation=https://github.com/crosbymichael/dockerui
After=docker.service
Requires=docker.service
[Service]
ExecStartPre=-/usr/bin/docker pull dockerui/dockerui
ExecStartPre=-/usr/bin/docker rm -f dockerui
ExecStart=/usr/bin/docker run --name dockerui -m 16M -v /var/run/docker.sock:/var/run/docker.sock dockerui/dockerui
@jamesmoey
jamesmoey / nginx_php5
Created August 1, 2014 23:56
Setup Nginx and PHP5 manifest
service { "php5-fpm":
ensure => running,
enable => true,
provider => init
}
service { "nginx":
ensure => running,
enable => true,
provider => init
@jamesmoey
jamesmoey / ExtendedArrayCollection.php
Last active July 24, 2023 07:02
Extend array collection from Doctrine with operation to perform on all the item in the collection.
<?php
namespace Collections;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\PropertyAccess\PropertyAccess;
class ExtendedArrayCollection extends ArrayCollection
{
/**
@jamesmoey
jamesmoey / menu.js
Last active December 20, 2015 03:49
(function() {
var menuLevel = 0;
var module = angular.module("merp.base.menu", ['ui.bootstrap']);
module.directive('menubar', ['$location', function($location) {
return {
restrict: 'E',
scope: {},
transclude: true,
replace: false,
template: '<div class="navbar"><div class="navbar-inner" ng-transclude></div></div>',