Skip to content

Instantly share code, notes, and snippets.

@oodavid
oodavid / dump.js
Last active December 11, 2015 21:38
This function acts like PHPs native print_r or var_dump and will dump out ANY variable to the console. Originally written for Appcelerator Titanium (using Ti.API.info instead of console.log) but tweaked to work with the console. There are plenty of alternatives to this, however I wanted to write my own so I could control the format / have a go :-)
/**
* DUMP
*
* Dumps a variable in a readable form to the console, this is a recursive function
* so be careful of nested references that may cause it to overflow... (untested for that)
*
* @v ANYTHING [Any variable]
* @name STRING [The name of the variable, optional, used internally when looping objects and arrays]
* @spacing STRING [The prefix spacing, used internally when looping objects and arrays]
*/
@oodavid
oodavid / Titanium Build Script for Sublime-Text-2
Last active December 9, 2015 23:29
Titanium Build Script for Sublime-Text-2
Once you have Titanium running, including Command-Line-Interface, this build script can be used with sublime-text to compile and pass to the attached android device.
Note that on windows you will probably need an additional "shell" parameter...
## Useful References
* https://wiki.appcelerator.org/display/guides/Titanium+Command+Line+Interface
* http://unbounded.io/post/28394170197/titanium-mobile-develpoment-with-sublime-text-2-and
* http://www.slideshare.net/cb1kenobi/exploring-the-titanium-cli-codestrong-2012
@oodavid
oodavid / README.md
Created June 20, 2012 13:32
MySQL to Structured Data (EXPERIMENT)

Found this little experiment in the depths of one of my projects; I've removed it and dumped it here in case I want it in the future

@oodavid
oodavid / primes.js
Created May 18, 2012 10:25
Prime Numbers Algorythm
/**
* You can check if a number is a prime by looping the known primes to see if it divides.
*/
// Seed the primes array
var primes = [2,3];
// Start counting up...
myCounter : for(n=5; n<10000; n+=2){
// Loop the known primes
for(p=0, l=primes.length; p<l; p++){
@oodavid
oodavid / README.md
Created April 12, 2012 20:01
MySQL - Group by grid-square

MySQL - Group by grid-square

Inspired by the police.uk crime maps, where they cleverly cluster data together depending on how far zoomed in you are, this MySQL snippet goes a long way to explaining the logic behind such an operation.

A perfect grid

This snippet groups sites to a perfect grid while the police.uk algorithm has some sort of trickery that moves their points about somewhat, looking at their blogs and documentation I would conclude that they have a predefined set of points, each with a catchment area of postcodes. It looks like a whole lot of scraping and manual labour went into their database and quite frankly I don't have the time nor inclination do attempt such a task.

Example

@oodavid
oodavid / README.md
Created April 9, 2012 21:41
Sync ./uploads/ with Amazon S3

Sync ./uploads/ with Amazon S3

This is a simple way to Sync a folder with Amazon S3 for a nightly backup - this is all to be done on your server :-)

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc

# Install s3cmd

cd /etc/yum.repos.d/

@oodavid
oodavid / README.md
Created April 6, 2012 13:39
XFCE - "Open any file" via Keyboard Shortcut

Linux - "Open any file" via Keyboard Shortcut

Assign this little shell script to a keyboard shortcut Xfce to open a shell -prompt, then have that file / directory opened by it's native program.

Pretty simple, excellent user-experience!

Thanks to Xfce forum member "ToC" who helped me solve a problem with the script

How to install

@oodavid
oodavid / recursive_killing.js
Created March 30, 2012 08:10
Recursive Killing
// Build a deep object of some sort
var ob = {
type: 'windar',
title: 'Hello World',
children: [
{
type: 'BUTTUN',
title: 'click me',
},
{
@oodavid
oodavid / README.md
Created March 27, 2012 08:29
CentOS AMP Server Setup

CentOS AMP Server Setup

I think I'd like to write (for fairly perverse reasons) a script that will setup something like this on a CentOS server:

  • Got CentOS?
  • Got root?
    • Update CentOS
    • Set hostname, timezone etc
    • Install Apache, MySQL, PHP, ImageMagick, S3cmd, Git etc.
  • Setup Git with Apache user and pull from github / bitbucket to /var/www/html/
@oodavid
oodavid / README.md
Created March 26, 2012 21:21
Restore MySQL from Amazon S3

Restore MySQL from Amazon S3

This is a hands-on way to pull down a set of MySQL dumps from Amazon S3 and restore your database with it

Sister Document - Backup MySQL to Amazon S3 - read that first

1 - Set your MySQL password and S3 bucket, make a temp dir, get a list of snapshots

# Set our variables

export mysqlpass="ROOTPASSWORD"