Skip to content

Instantly share code, notes, and snippets.

View tobsn's full-sized avatar

Tobsn tobsn

  • US/EU/SEA
View GitHub Profile
@tobsn
tobsn / gist:11258483
Created April 24, 2014 15:18
php false true null horse;
<?php
echo true ? 'car' : true ? 'horse' : 'feet'; #horse
echo true ? 'car' : false ? 'horse' : 'feet'; #horse
echo false ? 'car' : false ? 'horse' : 'feet'; #feet
echo false ? 'car' : true ? 'horse' : 'feet'; #horse
echo false ? 'car' : null ? 'horse' : 'feet'; #feet
echo true ? 'car' : null ? 'horse' : 'feet'; #horse
echo null ? 'car' : null ? 'horse' : 'feet'; #feet
echo null ? 'car' : false ? 'horse' : 'feet'; #feet
echo null ? 'car' : true ? 'horse' : 'feet'; #horse
@tobsn
tobsn / gist:11258555
Created April 24, 2014 15:20
get random geo location points within a radius
<?php
function getLocation( $y0, $x0, $rad ) {
$rad = $rad / 111195.0;
echo '$rad: '.$rad."\n";
$u = (float)mt_rand() / (float)getrandmax();
$v = (float)mt_rand() / (float)getrandmax();
echo 'rand: '.$v.' '.$u."\n";
@tobsn
tobsn / curl.php
Last active August 29, 2015 14:01
curl request via CLI
<?php
function clearCookies($cookiejar = 'cookies') {
@unlink($cookiejar);
}
function POSTURL(
$url,
$referer = "",
$data = array(),
@tobsn
tobsn / base
Created May 28, 2014 14:28
nginx - sub_filter replace head with the current folder as base href for sub project folder structure
location / {
if ($uri ~* ^/([^.\?/]+)) {
set $foldername "$1";
}
sub_filter "<head>" "<head><base href=\"${scheme}://${host}/${foldername}/\">";
}
@tobsn
tobsn / index.html
Created June 6, 2014 12:55
employee rating
<html>
<head>
<meta charset="utf-8">
<title>Who Am I?</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.2/raphael-min.js"></script>
@tobsn
tobsn / script.js
Last active August 29, 2015 14:02
replace query variables within static html with javascript and jQuery as selector
// http://jsfiddle.net/96q4m/17/ - old
// simulating GET variables
if(window.location.search.indexOf('test') < 0) window.location.search = window.location.search+'?test=123&img=https%3A%2F%2Fdrupal.org%2Ffiles%2Ftest-all-the-things.jpg';
// remove everything above this line - stop removing after
// closure compiled:
$(function(){function a(a){return decodeURIComponent(a.replace(b," "))}for(var b=/\+/g,c=/([^&=]+)=?([^&]*)/g,d=window.location.search.substring(1);y=c.exec(d);)$("#tpl-"+a(y[1])).length&&("IMG"!==$("#tpl-"+a(y[1]))[0].tagName?$("#tpl-"+a(y[1])).html(a(y[2])):$("#tpl-"+a(y[1])).attr("src",a(y[2])))});
@tobsn
tobsn / FormBuild.php
Last active August 29, 2015 14:15
Laravel 4.2 UrlGenerator and FormBuilder fixes for relative URLs for scheme-less URLs
<?php namespace Common;
use \Illuminate\Html\FormBuilder;
class FormBuild extends FormBuilder {
protected function getRouteAction( $options ) {
if( is_array( $options ) ) {
return $this->url->route( $options[0], array_slice( $options, 1 ), 0 );
}
return $this->url->route( $options, [], 0 );
@tobsn
tobsn / .htaccess
Created April 10, 2015 12:42
slim smarty gump yamop (mongodb)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})