Skip to content

Instantly share code, notes, and snippets.

View sydlawrence's full-sized avatar

Syd Lawrence sydlawrence

View GitHub Profile
@sydlawrence
sydlawrence / grid snap
Created December 17, 2012 10:35
snap position to grid
// taken from http://24ways.org/2012/cut-copy-paste/
snappedXpos = floor( xPos / gridSize) * gridSize;
@sydlawrence
sydlawrence / distance
Created December 17, 2012 10:37
Calculate the distance between two objects
// taken from http://24ways.org/2012/cut-copy-paste/
deltaX = round(p2.x-p1.x);
deltaY = round(p2.y-p1.y);
diff = round(sqrt((deltaX*deltaX)+(deltaY*deltaY)));
@sydlawrence
sydlawrence / mongo.backup.sh
Created March 12, 2013 10:29
simple s3 mongo backup using s3cmd
#!/bin/bash
#Force file syncronization and lock writes
mongo admin --eval "printjson(db.fsyncLock())"
MONGODUMP_PATH="/usr/bin/mongodump"
MONGO_HOST="127.0.0.1" #replace with your server ip
MONGO_PORT="27017"
MONGO_DATABASE="instawall" #replace with your database name
#!/bin/bash
TIMESTAMP=`date +%F-%H%M`
S3_BUCKET_NAME="wmasbackups" #replace with your bucket name on Amazon S3
S3_BUCKET_PATH="user-backups"
USER_NAME="syd"
echo "compressing user folder"
# Compressing
tar cf $USER_NAME-$HOSTNAME-$TIMESTAMP.tar /home/$USER_NAME/
@sydlawrence
sydlawrence / gist:5407013
Last active December 16, 2015 08:39
Sending an SMS via PHP.
<?php
// include the twilio php help library
require "Services/Twilio.php";
// Setup your credentials
$account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$auth_token = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
// Step 3: instantiate a new Twilio Rest Client
@sydlawrence
sydlawrence / WMAS woz ere
Last active December 17, 2015 23:59
WMAS HTML tag
<!--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
/\/\ WMAS woz 'ere \/\/ Client Name Here \/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-->
@sydlawrence
sydlawrence / twitterregs.js
Last active December 18, 2015 09:19
Simple JS to add the twitter "new guidlines" bs
function addTwitterBSRegs(id) {
var html = "<a class='reply' target='_blank' href='https://twitter.com/intent/tweet?in_reply_to="+id+"'>reply</a>";
html += "<a class='retweet' target='_blank' href='https://twitter.com/intent/retweet?tweet_id="+id+"'>retweet</a>";
html += "<a class='star' target='_blank' href='https://twitter.com/intent/favourite?tweet_id="+id+"'>star</a>";
html += "<a class='twitter' target='_blank' href='https://twitter.com/'>twitter</a>";
return html;
}
@sydlawrence
sydlawrence / gist:6130295
Created August 1, 2013 10:44
Tweet buttons
var reply = "https://twitter.com/intent/tweet?in_reply_to="+tweet.id;
var retweet = "https://twitter.com/intent/retweet?tweet_id="+tweet.id;
var star = "https://twitter.com/intent/favourite?tweet_id="+tweet.id;
@sydlawrence
sydlawrence / forward.sms.php
Created August 28, 2013 13:46
Forward SMS via Twilio
<?php
$to = "+447515354472";
?>
<Response>
<Sms to="<?php echo $to;?>" from="<?php echo $_POST['From'];?>"><?php echo $_POST['Body']; ?></Sms>
</Response>
@sydlawrence
sydlawrence / userlocation.js
Created September 25, 2013 22:03
Get User Location
navigator.geolocation.getCurrentPosition(function(result) {
var location = data.coords;
// This now consists of:
// latitude
// longitude
// altitude (if avaiable)
// various other attributes