Skip to content

Instantly share code, notes, and snippets.

View a1phanumeric's full-sized avatar

Ed Rackham a1phanumeric

  • Select Trade Brands
  • Torbay, UK
View GitHub Profile
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^00\.00\.00\.00 # Put your IP here
RewriteRule .* http://www.google.com [R=302,L]
@a1phanumeric
a1phanumeric / gist:2249553
Created March 30, 2012 08:23
Convert MKMapView touch to coordinate
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0;
[self.mapView addGestureRecognizer:lpgr];
// ---------------------------------
- (void)handleLongPress:(UIGestureRecognizer *)gestureRecognizer{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)return;
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchCoordinate =
@a1phanumeric
a1phanumeric / gist:2308893
Created April 5, 2012 08:04
How to sort by average user rating correctly
SELECT widget_id, ((positive + 1.9208) / (positive + negative) - 1.96 * SQRT((positive * negative) / (positive + negative) + 0.9604) / (positive + negative)) / (1 + 3.8416 / (positive + negative)) AS ci_lower_bound FROM widgets ORDER BY ci_lower_bound DESC;
@a1phanumeric
a1phanumeric / gist:2645144
Created May 9, 2012 14:59
Get array from ENUM def in MySQL yo x
<?php
// Change the following:
// TABLE_NAME = the name of your table
// COLUMN_NAME = the name of your column with an enum type
$result = mysql_query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TABLE_NAME' AND COLUMN_NAME = 'COLUMN_NAME'");
if(mysql_num_rows($result) == 1){
$remove = array('enum(', ')', "'");
$row = mysql_fetch_assoc($result);
$array = explode(',', str_replace($remove, '', $row['COLUMN_TYPE']));
@a1phanumeric
a1phanumeric / gist:3033803
Created July 2, 2012 15:30
Calculate luminosity of an image.
NSArray* dayArray = [NSArray arrayWithObjects:@"Image One",@"Image Two",@"Image Three",nil];
for(NSString* day in dayArray)
{
for(int i=1;i<=2;i++)
{
UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png",day,i]];
unsigned char* pixels = [image rgbaPixels];
double totalLuminance = 0.0;
for(int p=0;p<image.size.width*image.size.height*4;p+=4)
{
@a1phanumeric
a1phanumeric / gist:3907827
Created October 17, 2012 20:07
FizzBuzz One Liner
// PHP FizBuzz Solution
// Trying to get lowest bytecount.
// P.S. Yes, I know it's in PHP yadda-yadda-yadda
for($i=1;$i<=100;$i++)print((($i%15==0)?'FizzBuzz':(($i%5==0)?'Buzz':(($i%3==0)?'Fizz':$i)))."\n");
@a1phanumeric
a1phanumeric / gist:3910889
Created October 18, 2012 10:21
Project Euler - Problem 1
#include <stdio.h>
int main(){
int i;
int total;
for(i = 0; i<1000; i++) total+=(i%3==0 || i%5==0) ? i : 0;
printf("%i", total);
printf("\n");
return 0;
}
@a1phanumeric
a1phanumeric / gist:3911339
Created October 18, 2012 11:54
Project Euler - Problem 2
/*
* Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
* 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
* By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
*/
#include <stdio.h>
int previousSteps[] = {1,2};
int total = 2;
@a1phanumeric
a1phanumeric / gist:3958363
Created October 26, 2012 11:54
Touch everything in the current directory
find . -exec touch {} \;
@a1phanumeric
a1phanumeric / gist:4284074
Created December 14, 2012 09:39
Removes files older than one day
<?php
// Removes files older than a day
$dir = '/path/to/dir';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$filelastmodified = filemtime($dir . '/' . $file);
$filetype = filetype($dir . '/' . $file);