Skip to content

Instantly share code, notes, and snippets.

View MattSurabian's full-sized avatar

Matthew Surabian MattSurabian

View GitHub Profile
@MattSurabian
MattSurabian / ArrayUniqueAlternative.php
Created May 5, 2013 19:56
A gist demonstrating a faster method to unique arrays in PHP. Embeded on my blog: http://mattsurabian.github.io/PHP/a-better-way-to-unique-arrays-in-php/
// array_unique is WAY TOO SLOW! This method is significantly faster.
array_flip(array_flip($arr));
// If you need new keys generated use array_keys
array_keys(array_flip($arr));
@MattSurabian
MattSurabian / MultipleInputOptions.php
Created May 5, 2013 20:39
The method I use when validating multiple input options in class setters. Embeded in my blog post http://mattsurabian.github.io/PHP/validating-multiple-input-options-in-php
if (!in_array(strtolower($input), array('always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'))){
return false;
//or throw an exception
}
mergeObjects: function(){
var mergedObj = {};
for (var i = 0, max=arguments.length; i !== max; i++) {
var obj = arguments[i];
for (var key in obj) {
if( obj.hasOwnProperty(key) ) {
if( mergedObj[key] ) {
mergedObj[key] += obj[key]
}
else {
@MattSurabian
MattSurabian / filibuster.js
Created June 26, 2013 16:46
FilibusterJS: The unfortunately life like filibuster simulator.
var issue = 'solve this mess';
var secretArgueTime = Math.floor(Math.random()*86400000); // If only it didn't actually boil down to this
filibuster = setInterval(function(){
console.log('We must '+issue);
},500);
opposition = setInterval(function(){
console.log('Never!');
},500);
@MattSurabian
MattSurabian / PackerPolicy.json
Last active May 27, 2022 21:46
Minimum IAM policy required by AWS for Packer to do its thing. https://github.com/mitchellh/packer Permissions are broken out by API functionality and a resource array has been defined with a wild card for each group. For tighter security resource level permissions can be applied per this documentation: http://aws.typepad.com/aws/2013/07/resourc…
{
"Statement": [
{
"Sid": "PackerSecurityGroupAccess",
"Action": [
"ec2:CreateSecurityGroup",
"ec2:DeleteSecurityGroup",
"ec2:DescribeSecurityGroups",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:RevokeSecurityGroupIngress"
@MattSurabian
MattSurabian / newtonianSqrtTutorial.go
Created July 12, 2013 16:16
My implementation of the Newtonian Square Root Approximation in Go. Part of the Go tour: http://tour.golang.org/#23
package main
import (
"fmt"
"math"
)
const(
ACCURACY_DELTA = 0.00000000000001 // Experiment with this value to see accuracy impact!
)
@MattSurabian
MattSurabian / Pic.go
Last active December 19, 2015 17:39
My implementation of Pic in Go. Part of the Go tour: http://tour.golang.org/#35
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
picData := make([][]uint8, dy)
for y := range picData {
picData[y] = make([]uint8, dx)
@MattSurabian
MattSurabian / WordCount.go
Created July 14, 2013 04:52
My implementation of WordCount in Go. Part of the Go tour: http://tour.golang.org/#40
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
@MattSurabian
MattSurabian / FibonacciClosure.go
Created July 14, 2013 05:32
Implementation of a Fibonacci Closure in Go. Part of the Go tour: http://tour.golang.org/#43
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
var m1, m2 int
return func() int {
res := m1 + m2
@MattSurabian
MattSurabian / NewtonianCubeRoot.go
Created July 14, 2013 06:06
My implementation of the Newtonian Cube Root Approximation using complex numbers in Go. Part of the Go tour: http://tour.golang.org/#47
package main
import "fmt"
import "math/cmplx"
import "math"
const(
ACCURACY_DELTA = 0.0000000000000001
)