Skip to content

Instantly share code, notes, and snippets.

View jrmadsen67's full-sized avatar
💭
Looking for new remote opportunities

Jeff Madsen jrmadsen67

💭
Looking for new remote opportunities
View GitHub Profile
@jrmadsen67
jrmadsen67 / called.in wrapper for Codeigniter
Created March 10, 2012 08:54
called.in wrapper for Codeigniter
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Calledin{
private $ci;
private $messages = array(
0=>'Success',
1=>'invalid api_key',
2=>'no call credits',
@jrmadsen67
jrmadsen67 / multi-checkbox in list
Created November 5, 2012 23:21
simple div with multi-list checkboxes
<style>
.scroll_checkbox {
border: 1px solid #CCCCCC;
height: 200px;
overflow: auto;
padding: 5px;
width: 250px;
}
</style>
@jrmadsen67
jrmadsen67 / gist:4052790
Created November 10, 2012 22:35
example of map_array() with "use" to pass in variable
function map_array()
{
$names = array('Foo', 'Bar', 'Baz', 'Buzz');
$tweeps = array();
foreach ($names as $name) {
$tmp = new StdClass;
$tmp->name = $name;
$tmp->age = rand(2,7);
@jrmadsen67
jrmadsen67 / gist:4054208
Created November 11, 2012 08:56
php - create days of week array from functions
$date = new DateTime('first Sunday');
$weeksdays_array = array_map(function($val) use ($date) {return $date->add(new DateInterval('P'.$val.'D'))->format('l');}, range(0,6));
var_dump($weeksdays_array);
@jrmadsen67
jrmadsen67 / gist:4274093
Created December 13, 2012 04:50
git cleanup script. sets all deleted files to git rm <file>
for i in `git status |grep deleted |awk '{print $3}'` ; do git rm $i; done
@jrmadsen67
jrmadsen67 / CI dynamic dropdown
Created January 5, 2013 08:00
A CodeIgniter dynamic dropdown to allow common languages to appear both at the top of the list and in order
function full_languages_dropdown($id='' )
{
$ci = &get_instance();
$ci->load->model('language_model');
$common_languages = $ci->language_model->order_by('language', 'asc')->get_many_by(array('common'=>1));
$languages = $ci->language_model->order_by('language', 'asc')->dropdown('id', 'language');
$html = '<select id="'.$id.'" name="'.$id.'">';
@jrmadsen67
jrmadsen67 / gist:4618291
Last active December 11, 2015 14:59
jquery function to move focus to next element of group when max length hit. for use with phone numbers, dates, etc
// assumes you set tabIndex="0" ... last element in group
// set all elements in group with same class
// set each element with max length
// obviously, "phones" is not generic, easy to switch. Code I just wrote for something quick; will fix that later
$('.phone').keyup(function(){
jumpNext($(this), $(this).val())
});
@jrmadsen67
jrmadsen67 / gist:4695757
Created February 2, 2013 02:18
Playing around with callbacks in array_map. Notice array($this, 'process') lets you specify an object->method, perfect for use in framework controller (like in Codeigniter)
<?php
$main_object = new main_object();
$main_object->main();
class main_object{
function main()
{
@jrmadsen67
jrmadsen67 / gist:5028002
Last active December 14, 2015 04:28
Takes data from a key:value table & combines it onto a single-row record, per item
/*
Data starts in table:
ProjectId, key, value
1 totaltime 02:34:56
1 zip.url http://www.mysite.com/download/file.zip
1 zip.size 12MB
@jrmadsen67
jrmadsen67 / gist:5097167
Created March 6, 2013 06:25
Get preceding 12 month array, starting with 12 months earlier and ending in current month (ex. Today is Mar, so array will be Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Jan,Feb,Mar)
$date = new DateTime((date('Y')-1).'-'.date('m').'-01' ); //to kill the 31 day problem
$months_array = array_map(function($val) use ($date) {return $date->add(new DateInterval('P1M'))->format('M');}, range(1,12));