Skip to content

Instantly share code, notes, and snippets.

View jordanthomas's full-sized avatar
✌️
v chill

Jordan Thomas jordanthomas

✌️
v chill
View GitHub Profile
@jordanthomas
jordanthomas / gist:732375
Created December 7, 2010 20:43
json array of countries and codes
var countries = [
{'name':'AFGHANISTAN', 'code':'AF'},
{'name':'ÅLAND ISLANDS', 'code':'AX'},
{'name':'ALBANIA', 'code':'AL'},
{'name':'ALGERIA', 'code':'DZ'},
{'name':'AMERICAN SAMOA', 'code':'AS'},
{'name':'ANDORRA', 'code':'AD'},
{'name':'ANGOLA', 'code':'AO'},
{'name':'ANGUILLA', 'code':'AI'},
{'name':'ANTARCTICA', 'code':'AQ'},
@jordanthomas
jordanthomas / arr.php
Created April 5, 2011 15:21
Determines if an input array is multidimensional.
public function is_multi(array $array)
{
foreach ($array as $key => $value)
{
if (is_array($value))
return TRUE;
}
return FALSE;
}
@jordanthomas
jordanthomas / gist:1186425
Created September 1, 2011 15:29
Kohana random record method
public function find_random()
{
$row = DB::query(Database::SELECT,
'SELECT * FROM `'.$this->table_name.'` ORDER BY RAND() LIMIT 1')
->as_object(get_class($this))->execute($this->_db)->current();
return $row;
}
@jordanthomas
jordanthomas / params.js
Last active September 28, 2015 22:48
Automagic querystring params in js
window.params = (function() {
var obj = {},
pattern = new RegExp( '([^?=&]+)=?([^&]*)?','g' );
while ( match = pattern.exec( window.location.search ) ) {
obj[match[1]] = match[2] ? match[2] : true;
}
return obj;
})();
// Have jQuery?
if ( !Function.prototype.bind ) {
Function.prototype.bind = function ( obj ) {
args = [].slice.call( arguments );
args.unshift( this );
return $.proxy.apply( this, args );
};
}
@jordanthomas
jordanthomas / gist:2930740
Created June 14, 2012 14:37
Laravel Valdiated
<?php
Class Validated extends Eloquent {
public $rules = array();
public $errors;
public function __construct($attributes = array(), $exists = false)
{
@jordanthomas
jordanthomas / invites_controller.rb
Created October 9, 2012 00:32
nested resource errors
class InvitesController < ApplicationController
def create
@project = Project.find(params[:project_id])
@invite = @project.invites.build(params[:invite])
if @project.save
redirect_to project_url(@project), :notice => 'Success message.'
else
render # ?? project/show ??
end
class CommentsController < ApplicationController
respond_to :html, :json
def create
@report = Report.find(params[:report_id])
@comment = @report.comments.build(params[:comment])
@comment.user = current_user
respond_with @report, @comment, :methods => [:by_admin?]
end
end
@jordanthomas
jordanthomas / jquery.dealwithit.js
Created December 13, 2012 21:05
Deal With It for the web
(function ( $, window, document, undefined ) {
var pluginName = 'dealWithIt',
defaults = {
speed: 7000
};
function DealWithIt( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._defaults = defaults;
String::slugify = ->
map =
'à':'a'
'á':'a'
'ä':'a'
'â':'a'
'è':'e'
'é':'e'
'ë':'e'
'ê':'e'