Skip to content

Instantly share code, notes, and snippets.

@jbottigliero
jbottigliero / gist:5066194
Last active December 14, 2015 09:39
mongodb - random document(s)
// mongodb collection generator for getting random documents...
// set to the collection you wish to add a random attribute to.
var collection = 'myCollection',
// the name of the random collection to be generated; what you'll run queries against
// to obtain a random document
randCollection = 'rand' + collection.charAt(0).toUppderCase(),
// wheter or not the random collection should contain full documents, or a truncated
// version of the document (the mongo $_id and random attribute only)
useTruncatedDoc = false;
@jbottigliero
jbottigliero / gist:5008262
Created February 21, 2013 21:07
iterator_map_to_array PHP funciton
function iterator_map_to_array(\Iterator $iterator, $callback, $use_keys = true){
foreach($iterator as $i){
$i = $callback($i);
}
return iterator_to_array($iterator, $use_keys);
}
return iterator_map($cursor, function($i){
return new MyObject($i);
}, false);
@jbottigliero
jbottigliero / geo.js
Created February 18, 2013 17:16
node.js geo data. Initially populated via [Graphic Maniacs](http://graphicmaniacs.com/note/php-countries-array-us-states-array/)
var countries = {
AF: "Afghanistan",
AL: "Albania",
DZ: "Algeria",
AS: "American Samoa",
AD: "Andorra",
AO: "Angola",
AI: "Anguilla",
AQ: "Antarctica",
AG: "Antigua and Barbuda",
@jbottigliero
jbottigliero / crontaber
Created February 11, 2013 22:05
Add jobs to crontab quickly via CLI
job="@daily which node" && cat <(grep -v "$job" <(crontab -l)) <(echo "$job") | crontab -
@jbottigliero
jbottigliero / gist:3955492
Created October 25, 2012 21:20
ejabber, BOSH, and StopheJS, Oh My(SQL)

ejabberd

####Server Ubuntu 10.04 LTS Lucid

##Process

Install ejabberd

@jbottigliero
jbottigliero / .directions
Created June 28, 2012 21:46
MAMP : Virtual Hosts
# Backup your host file
sudo cp /etc/hosts /etc/hosts.bak
# Edit your host file
# See 'hosts.example' for example contents
vim /etc/hosts
# Edit MAMP Apache configuration to include Virtual Hosts configuration
@jbottigliero
jbottigliero / gist:2876556
Created June 5, 2012 17:54
CodeIgniter Pagination Library: Add ability to wrap `digits` with HTML markup.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
@jbottigliero
jbottigliero / MY_URI.php
Created June 5, 2012 16:37
CodeIgniter URI Library: Add offset functionality to the `uri_string` method.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
@jbottigliero
jbottigliero / toggleDisabled.html
Created April 30, 2012 19:58
jQuery Toggle Disabled
<input id="test_input" type="text" value=""/>
<button id="disabler">Disable Input</button>
<script>
$('#disabler').on('click', function(){
// No callback
// $('#test_input').toggleDisabled();
// With callback
$('#test_input').toggleDisabled(function(el, disabled){
@jbottigliero
jbottigliero / MY_Form_validation.php
Created April 12, 2012 06:21
(set_messages method) Add support for 'flash error messages' to CodeIgniter's built in Form Validation library.
<?php
class MY_Form_validation extends CI_Form_validation {
public function set_message($lang, $val = '', $name = FALSE)
{
if($name !== FALSE){
$lang = $name.'.'.$lang;
}