Skip to content

Instantly share code, notes, and snippets.

View jondavidjohn's full-sized avatar

Jonathan D. Johnson jondavidjohn

View GitHub Profile
@jondavidjohn
jondavidjohn / MY_Controller.php
Created July 8, 2011 19:56
Loading Multiple Databases with Codeigniter
<?php
/***
* filepath: application/core/MY_Controller.php
*/
//setup your base controller
class DB_Controller extends CI_Controller {
//declare them globally in your controller
protected $billing_db;
@jondavidjohn
jondavidjohn / component.js
Created July 10, 2011 04:46
Javascript Component Starting point
var component = (function($){
var default_options = {
array_option : [],
string_option : "default"
};
return {
other_function: function(args) {
@jondavidjohn
jondavidjohn / multi-form-submit.js
Created July 13, 2011 15:46
Submit Multiple Forms via AJAX
$('button').click(function() {
$('form').each(function() {
var action = $(this).attr("action");
var data = $form.serialize();
$.post(action, data);
});
});
@jondavidjohn
jondavidjohn / .bash_profile
Created July 20, 2011 18:34
Bash Alias to check for php errors on all Modified Files
function gitphpcheck () {
filearray=()
while read line; do
if [[ $line =~ ^(M|N) ]]
then
filename="`echo $line | awk '{ print $2 }'`"
filearray+=($filename)
@jondavidjohn
jondavidjohn / .gitconfig
Created July 21, 2011 03:43
Starter .gitconfig
[color]
diff = auto
status = auto
branch = auto
[user]
name = ***YOUR NAME***
email = ***YOUR EMAIL***
[core]
excludesfile = /path/to/global/.gitignore
editor = ***PREFERRED EDITOR***
@jondavidjohn
jondavidjohn / .profile
Created July 21, 2011 03:46
Include current Git branch in prompt
# this snippet rewrites your prompt to include the current branch if in a git repo
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\[\e[01;33m\]\w \$(parse_git_branch): \[\e[00m\]"
@jondavidjohn
jondavidjohn / base_m.php
Created July 21, 2011 04:21
Base Codeigniter Model
<?php if (! defined('BASEPATH')) exit('No direct script access');
class Base_m extends CI_Model {
protected $table_name;
protected $pk_field;
public function __construct()
{
parent::__construct();
@jondavidjohn
jondavidjohn / example.php
Created July 21, 2011 05:19
Gather data from form submission ( Codeigniter )
<?
$data = array();
foreach($_POST as $key => value)
{
if ( $this->input->post($key) ) // if a value is set
{
$data[$key] = $this->input->post($key, true); //protect against xss
}
}
@jondavidjohn
jondavidjohn / controller.php
Created July 21, 2011 05:39
Codeigniter: Remap params to index() function
<?
function _remap($method)
{
$param_offset = 2;
// Default to index
if ( ! method_exists($this, $method))
{
// We need one more param
@jondavidjohn
jondavidjohn / Activity.cs
Created August 2, 2011 16:40
Custom ListView with Custom Filtering (Mono for Android)
// grab input field to filter with
EditText etFilter = FindViewById(Resource.Id.studentFilter);
// call custom adapter filter method on TextChange
etFilter.TextChanged += delegate(object sender, Android.Text.TextChangedEventArgs e)
{
adapter.filterStudents(e.Text.ToString());
};