Skip to content

Instantly share code, notes, and snippets.

View tobsn's full-sized avatar

Tobsn tobsn

  • US/EU/SEA
View GitHub Profile
@richthegeek
richthegeek / cache_filter.php
Created March 8, 2012 16:24
Variable microcaching with Laravel
<?php
Route::filter('cache', function($response = NULL) {
$cname = 'response-' . Str::slug(URI::full());
if (!$response) {
return Cache::get($cname);
}
else if ($response->status == 200) {
$ctime = floor(pow(current(sys_getloadavg()) + 1, 5)); # cache for between 1 and 32 minutes
Cache::put($cname, $response, $ctime);
@mwesten
mwesten / auth.php
Created February 23, 2012 13:09
Laravel 3 Auth Controller
<?php
class Auth_Controller extends Base_Controller {
public $restful = true;
public function __construct() {
$this->filter( 'before', 'guest' )->except( array( 'logout', 'validate' ) );
// Note: We may not always require CSRF on login for system based logins so ignore it here.
$this->filter( 'before', 'csrf' )->on( 'post' )->except( array( 'login' ) );
}
@sangramanand
sangramanand / Elastic BeanStalk settings for Live Env
Created January 12, 2012 04:07
Elastic BeanStalk settings for Live Env
Live Environment Configuration on Elastic Beanstalk
Ec2-instance type - c1.medium
Ec2 Security Groups - elasticbeanstalk-default, default, GSUI-Base
Monitor Interval - 1 minute
Http Listener port -80
Https Listen ort -443
SSL Certificate ID - rn:aws:iam::228576831886:server-certificate/GeneralSentiment-SSL
Application Health Check URL - /
Health Check Interval (seconds) - 30
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@chjj
chjj / simple_request.js
Created May 19, 2011 22:46
simple request
var http = require('http')
, parse = require('url').parse
, StringDecoder = require('string_decoder').StringDecoder;
var LIMIT = 10 * 1024;
var request = function(url, body, func) {
if (typeof url !== 'object') {
url = parse(url);
}
@3rd-Eden
3rd-Eden / detect.client.socket.io.js
Created April 5, 2011 08:20
Serverside client transport detection for Socket.io
require.paths.unshift('/usr/local/lib/node/socket.io/lib/socket.io/transports');
var htmlfile = require('htmlfile')
, flashsocket = require('flashsocket')
, jsonppolling = require('jsonp-polling')
, websocket = require('websocket')
, xhrmultipart = require('xhr-multipart')
, xhrpolling = require('xhr-polling');
var http = require('http')
, io = require('socket.io');
@kosso
kosso / background_demo.js
Created March 12, 2011 17:55
Background Service notification for Titanium
/* Kosso : March 12th 2011
This the only way I managed to do this without the app crashing on resume.
Done slightly differently to the KS example, since they unregister the service and
do not use a setInterval timer.
*/
//############ in app.js :
// test for iOS 4+
@stagas
stagas / how-to-run-apache-and-node.js-together-the-right-way.markdown
Created December 24, 2010 14:45
How to run Apache and Node.js together (the right way)

Step 1

Get a VPS that offers 2 or more IP addresses.

Step 2

From the WHM cPanel, find the menu item Service Configuration, select Apache Configuration and then click on Reserved IPs Editor.

Step 3

@creationix
creationix / inspect.js
Created December 23, 2010 06:51
a custom object inspector to help me understand JavaScript
function escapeString(string) {
string = string.replace(/\\/g, "\\\\").
replace(/\n/g, "\\n").
replace(/\r/g, "\\r").
replace(/\t/g, "\\t");
if (string.indexOf("'") < 0) {
return "'" + string + "'";
}
string = string.replace(/"/g, "\\\"");
return '"' + string + '"';
@tobsn
tobsn / jquery.loader.js
Created December 10, 2010 19:50
there are many problems when you act as third party that offers a javascript file and you want to use jquery - this solved all of my problems. the little function checks if jquery is already embedded, includes it and waits until its loaded if its missing
(function(j,q,u,e,r,y,R,o,x){try{o=jQuery;if(o&&(!R||(R&&o.fn.jquery==R))){x=true}}catch(er){}if(!x||(R&&o.fn.jquery!=R)){(q=j.createElement(q)).type='text/javascript';if(r){q.async=true}q.src='//ajax.googleapis.com/ajax/libs/jquery/'+(R||1)+'/jquery.min.js';u=j.getElementsByTagName(u)[0];q.onload=q.onreadystatechange=(function(){if(!e&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){e=true;x=jQuery;jQuery.noConflict(true)(function(){y(x)});q.onload=q.onreadystatechange=null;u.removeChild(q)}});u.appendChild(q)}else{y(o)}})(document,'script','head',false,false,(function($){$(function(){
/* code goes here */
console.log($.fn.jquery);
})}));
// readable:
(function (j, q, u, e, r, y, R, o, x ) {
// IE8 undefined crash fix
try {