Skip to content

Instantly share code, notes, and snippets.

View bad-mushroom's full-sized avatar
😐
It's complicated.

Chris Sprague bad-mushroom

😐
It's complicated.
View GitHub Profile
<?php
function isPalindrome(string $word): bool
{
$hashMap = [];
for ($i = 0; $i < strlen($word); $i++) {
if (isset($hashMap[$word{$i}])) {
$hashMap[$word{$i}] = $hashMap[$word{$i}] + 1;
} else {
@bad-mushroom
bad-mushroom / pre-commit
Created September 29, 2016 15:25
Git pre-commit hook
#!/bin/sh
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
func getRandomColor() -> SKColor
{
var randomRed:CGFloat = CGFloat(drand48())
var randomGreen:CGFloat = CGFloat(drand48())
var randomBlue:CGFloat = CGFloat(drand48())
return SKColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0)
}
@bad-mushroom
bad-mushroom / gist:09b422ec05f0f455764d
Created December 19, 2014 21:18
Git Log (pretty) Placeholders
- '%H': commit hash
- '%h': abbreviated commit hash
- '%T': tree hash
- '%t': abbreviated tree hash
- '%P': parent hashes
- '%p': abbreviated parent hashes
- '%an': author name
- '%aN': author name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
- '%ae': author email
- '%aE': author email (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
-(int)randomNumberBetween:(int)from to:(int)to
{
return (int)from + arc4random() % (to-from+1);
}
@bad-mushroom
bad-mushroom / Send Email
Created November 14, 2014 02:19
Send email
-(void)sendEmailTo:(NSString *)to withSubject:(NSString *)subject withBody:(NSString *)body
{
NSString *mailString = [NSString stringWithFormat:@"mailto:?to=%@&subject=%@&body=%@",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
}
@bad-mushroom
bad-mushroom / gist:f930540d1c50d6bf701d
Created October 8, 2014 17:40
Work with ViewControllers Programatically
// Present VC from Storyboard
// (include VC's header file)
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"<STORYBOARD_NAME>" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"<STORYBOARD_ID"];
[self presentViewController:vc animated:FALSE completion:nil];
// Call Segue from Storyboard
[self performSegueWithIdentifier:@"<SEGUE_ID>" sender:self];
@bad-mushroom
bad-mushroom / gist:06acff36658e2caa322e
Created September 29, 2014 13:21
Shellshock Test
x='() { :;}; echo VULNERABLE' bash -c :
@bad-mushroom
bad-mushroom / post-receive deploy
Created March 28, 2014 23:11
post-receive hook for deploying site based on branch. "master" is pushed to the production site, "development" to the test site.
#!/bin/bash
echo '--- --- --- --- --- --- --- --- --- --- ---'
echo 'Deploying site...'
echo '--- --- --- --- --- --- --- --- --- --- ---'
if ! [ -t 0 ]; then
read -a ref
fi
IFS='/' read -ra REF <<< "${ref[2]}"
@bad-mushroom
bad-mushroom / grep | sed search-repalce
Last active August 29, 2015 13:57
Pipe results from grep to sed for search/replace
grep -lr <pattern> ./<dir> | xargs sed -i '' 's/<search-for>/<replace-with>/g'