Skip to content

Instantly share code, notes, and snippets.

View jonsherrard's full-sized avatar
💭
Working

Jon Sherrard jonsherrard

💭
Working
View GitHub Profile
@jonsherrard
jonsherrard / backbone-cakefile-snippet.coffee
Created September 17, 2012 06:04
Cakefile with delay
# Double check file structure before use
task 'build:coffee', 'build src/client.js file from source files', (options) ->
files = content = []
finished = {}
fs.readFile 'src/client/coffee/base.coffee', 'utf8', (err, contents) ->
content.push contents
for dir in ['views', 'collections', 'models'] then do (dir) ->
delay = (ms, func) -> setTimeout func, ms
if dir is 'models'
@jonsherrard
jonsherrard / distance.coffee
Created September 20, 2012 17:04
Coffeescript to convert to latitudes and longitudes into a distance
distance = (lat1, lon1, lat2, lon2) ->
R = 6371 # km (change this constant to get miles)
dLat = (lat2 - lat1) * Math.PI / 180
dLon = (lon2 - lon1) * Math.PI / 180
a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2)
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
d = R * c
if d > 1
return d + "km"
else return Math.round(d * 1000) + "m" if d <= 1
@jonsherrard
jonsherrard / horrible.sql
Created September 21, 2012 14:49
horrible sql
Select *,
acos(sin($lat)*sin(radians(event_latitude)) + cos($lat)*cos(radians(event_latitude))*cos(radians(event_longitude)-$lon))*$R As distance
From (
Select search_view.*, images.image_url
From search_view, images
Where search_view.event_image_id = images.image_id
AND event_start > ?
And event_latitude>$min_lat And event_latitude<$max_lat
And event_longitude>$min_lon And event_longitude<$max_lon
) As FirstCut
@jonsherrard
jonsherrard / query.js
Created September 21, 2012 15:11
query.js
function rad2deg (angle) {
return angle * 57.29577951308232; // angle / Math.PI * 180
}
function deg2rad (angle) {
return angle * .017453292519943295; // (angle / 180) * Math.PI;
}
function get_events (input_lat, input_lon) {
lat = input_lat;
@jonsherrard
jonsherrard / active_game.php
Created October 8, 2012 14:46
active_game.php
$this->facebook_id = $facebook_id;
$active_game = array_filter($games, function($game) {
return $game->active;
});
if (count($active_game) > 1):
$active_game = array_filter($active_game, function($game) {return $game->creator === $this->facebook_id;});
endif;
if (count($active_game)) $active_game[0]->garments = $this->get_garments($active_game[0]->game_id);
return $active_game[0];
@jonsherrard
jonsherrard / active_game.php
Created October 8, 2012 15:08 — forked from benhartley/active_game.php
active_game.php
<?
$this->facebook_id = $facebook_id;
$active_game = array_filter($games, function($game) {
return $game->active;
});
/*
# Not sure this is needed, the game with the lowest game_id should be returned.
if (count($active_game) > 1):
@jonsherrard
jonsherrard / active_game.php
Created October 8, 2012 15:11 — forked from benhartley/active_game.php
active_game.php
<?
$this->facebook_id = $facebook_id;
$active_game = array_filter($games, function($game) {
return $game->active;
});
/*
# Not sure this is needed, the game with the lowest game_id should be returned.
if (count($active_game) > 1):
@jonsherrard
jonsherrard / probs.php
Created November 27, 2012 13:14
idorm stuff
<?php
public function getAllPrizes() {
return ORM::forTable("prizes")->findMany();
}
var_dump(
$db->getAllPrizes()[0]->as_array()
);
@jonsherrard
jonsherrard / vimflowy.js
Last active December 13, 2015 21:18
A Userscript compatible version of VimFlowy plugin for Workflowy - https://github.com/thricedotted/vimflowy
function enterNormalMode() {
console.log("entering normal mode");
$(".editor > textarea").bind("keydown", blockAll);
$(".editor > textarea").addModalKeyboardShortcuts(normalKeybindings, insertKeybindings)
}
function enterInsertMode(e) {
e.preventDefault();
console.log("entering insert mode");
$(".editor > textarea").unbind("keydown", blockAll);
$(".editor > textarea").addModalKeyboardShortcuts(insertKeybindings, normalKeybindings)