Skip to content

Instantly share code, notes, and snippets.

@phawk
phawk / destroy.js
Created July 2, 2012 15:05
destroy.js
destroy: function() {
// Cleanup any events
$(this.el).undelegate();
// Remove the element from the DOM
$(this.el).remove();
return this;
}
@phawk
phawk / js-namespace.js
Created June 16, 2012 15:17
JS Namespace function
// Core namespace
var app = app || {};
app.namespace = function(namespace) {
var spaces = namespace.split('.');
var nspace = function(spaces, index, progress) {
// Check the namespace exists
if (typeof spaces[index] === "undefined") { return; }
@phawk
phawk / gist:2759513
Created May 20, 2012 20:59
conditions better.
def some_method
if [email protected]?
goToLoginScreen
end
if [email protected]?
throwSomeUnathorisedError
end
#continue writing your code
@phawk
phawk / gist:2759486
Created May 20, 2012 20:50
conditions bad.
def some_method
if @user.isLoggedIn?
if @user.isAdmin?
...
else
throwSomeUnathorisedError
end
else
goToLoginScreen
end
@phawk
phawk / gist:2700655
Created May 15, 2012 10:27
Frontend tests
require 'watir-webdriver'
require 'test/unit'
require './helper_methods.rb'
class TKP_frontend_tests < Test::Unit::MiniTest
# Mixin the helper methods
include HelperMethods
@phawk
phawk / gist:2700650
Created May 15, 2012 10:26
helper methods
module HelperMethods
def open_browser
puts "Open a browser (chrome)"
@browser = Watir::Browser.new :chrome
return @browser
end
def tkp_admin_url
"http://frontend.example.com/admin"
@phawk
phawk / jQuery multiple autotabs.js
Created February 8, 2012 12:02
jQuery multiple autotabs
<script type="text/javascript">
var doc = {
init: function()
{
// Setup first group
doc.structureTabs('#tabs');
jQuery("#tabs").tabs();
// Setup second group
<?php
public function get_record( $primary_value )
{
$this->db->where( $this->primary_key, $primary_value );
$this->db->from( $this->table_name );
$query = $this->db->get();
if( $query->num_rows() === 1 )
{
<?php
class Users_model extends MY_Model
{
public function __construct()
{
parent::__construct();
/* Set Table info */
<?php
$parent_path = dirname( $_SERVER['DOCUMENT_ROOT'] );
define('SHAREDPATH', $parent_path . '/shared/');