Skip to content

Instantly share code, notes, and snippets.

View alloyking's full-sized avatar
🎧
.

Tim Shultis alloyking

🎧
.
View GitHub Profile
@alloyking
alloyking / sammy-json.js
Created December 1, 2012 02:23
Sammy remote json load
//parse json plugin
(function($) {
Sammy.JSON.LoadJSON = function(app) {
app.helpers({
loadJSON: function(location, options, callback) {
options = $.extend(options, {json: true});
return new Sammy.RenderContext(this).load(location, options, callback);
}
});
}
@alloyking
alloyking / async_curl.php
Created December 21, 2012 06:59
async curl request
// $type must equal 'GET' or 'POST'
function curl_request_async($url, $params, $type='POST')
{
foreach ($params as $key => &$val) {
if (is_array($val)) $val = implode(',', $val);
$post_params[] = $key.'='.urlencode($val);
}
$post_string = implode('&', $post_params);
$parts=parse_url($url);
@alloyking
alloyking / cache.js
Last active December 11, 2015 03:58
cache function result
function isPrime( num ) {
if ( isPrime.cache[ num ] != null )
return isPrime.cache[ num ];
var prime = num != 1; // Everything but 1 can be prime
for ( var i = 2; i < num; i++ ) {
if ( num % i == 0 ) {
prime = false;
break;
}
@alloyking
alloyking / client-fallback
Created January 23, 2013 16:28
websocket polling fallback
ioSocket = io.connect("http://www.mydomain:443/chatserver");
ioSocket.of('/chatserver').on('connect', function()
{
// Everything works fine
console.info("Connected to Chat-server");
}).on('connect_failed', function(reason)
{
/* Connection failed. This can have many reasons.
One possible reason is the blocking of port 443 which I used above.
Declarations with var: Always
var
Constants:
Use NAMES_LIKE_THIS for constant values.
Never use the const keyword as it not supported in Internet Explorer.
If a value is intended to be constant and immutable, it should be given a name in CONSTANT_VALUE_CASE. ALL_CAPS additionally implies @const (that the value is not overwritable
ex:
TIMEOUT_IN_MILLISECONDS = 60;
// Require.js allows us to configure shortcut alias
require.config({
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
'socketio': {
exports: 'io'
},
'underscore': {
exports: '_'
@alloyking
alloyking / Validator.php
Created August 12, 2013 12:25
Laravel abstact validator
<?php namespace Services\Validators;
abstract class Validator {
protected $attributes;
public $errors; //allow access to error messages
public function __construct($attributes = null){
@alloyking
alloyking / Step1.php
Created August 12, 2013 12:26
Laravel extend validator
<?php namespace Services\Validators;
class Step1 extends Validator{
//rules for step1 validation
public static $rules = array(
'email' => 'required',
'firstname' => 'required',
'lastname' => 'required',
'system_key' => 'required|systemcheck',
@alloyking
alloyking / RegisterController.php
Created August 12, 2013 12:29
Laravel controller validator
<?php
class RegisterController extends BaseController {
protected $layout = 'layouts.master';
//post
public function post_index(){
$validation = new Services\Validators\Step1;
@alloyking
alloyking / bundle.php
Last active December 21, 2015 17:38
Symphonycms php 5.4
<?php
/**
* @package boot
*/
if(!defined('PHP_VERSION_ID')){
$version = PHP_VERSION;
/**