Skip to content

Instantly share code, notes, and snippets.

View rmcvey's full-sized avatar
Black Lives Matter

Rob McVey rmcvey

Black Lives Matter
View GitHub Profile
@rmcvey
rmcvey / filtered.html
Created November 29, 2011 19:56
Filtered Search
<DOCTYPE!>
<html>
<head>
<title>Filtered Search</title>
<script type="text/javascript" src="https://raw.github.com/rmcvey/jsper/master/jsper.js"></script>
<script type="text/javascript">
window.onload = function(){
var saved = document.getElementById('saved');
jsper.each('filters', function(item){
var element = document.createElement('option');
@rmcvey
rmcvey / element.js
Created July 3, 2012 16:32
DOM element factory
var element = {
create: function(tag_type, attributes){
var el = document.createElement(tag_type)
, styles = attributes['style'] || []
, i
, x
, style_string = '';
delete attributes['style'];
@rmcvey
rmcvey / supplant.js
Created January 22, 2013 17:20
personally, I feel like a library is frequently (but not always) overkill when all you want is variable substitution
String.prototype.supplant = function (o) {
o = o || {};
return this.replace(/{([^{}]*)}/g, function(bracketed, clean){
var object_value = o[clean];
return ['string', 'number'].indexOf((typeof object_value)) > -1 ? object_value : bracketed;
})
}
//example
var text = "{name} is feeling {feeling}".supplant({
@rmcvey
rmcvey / javascript_event_wrapper.js
Last active December 11, 2015 16:59
Allows chaining when adding event handlers
// versatile method
Object.prototype.pushEvent = function(action, fn, bubbleStage) {
fn = fn || function(ev){};
bubbleStage = bubbleStage || false;
if('length' in this) {
for(var x = 0; x < this.length; x++){
this[x].pushEvent(action, fn, bubbleStage)
}
} else {
this.addEventListener(action, fn, bubbleStage || false);
/**
* I wrote a much more robust storage facade called jsper <https://github.com/rmcvey/jsper>, this is more lightweight
* javascript html5 storage wrapper with fallback to cookies
* @author Rob McVey
* @license MIT License
*/
var storage = ( function( context ) {
// just use cookies if not HTML5
var fallback;
$.fn.placeholder = function(text){
if(typeof text !== 'undefined'){
this.attr('data-placeholder', text);
} else {
return this.attr('data-placeholder');
}
var that = $(this)
if(that.val('')){
that.val(text);
}
cd /tmp
curl -O http://us3.php.net/distributions/php-5.3.13.tar.bz2
tar -xjvf php-5.3.13.tar.bz2
cd php-5.3.13
sudo ./configure --prefix=/opt/amp --with-libdir=lib --with-config-file-path=/opt/amp/etc \
--with-config-file-scan-dir=/opt/amp/etc/php.d --enable-phar --disable-debug --enable-inline-optimization \
--with-bz2 --without-gdbm --enable-cli --enable-gd-native-ttf --with-xmlrpc --with-pcre-regex --with-zlib \
--with-layout=GNU --enable-bcmath --enable-exif --enable-ftp --enable-sockets --enable-sysvsem --enable-sysvshm \
--enable-sysvmsg --enable-wddx --with-pear --enable-shmop --enable-calendar --enable-mbstring --enable-mbregex \
--with-apxs2=/opt/amp/bin/apxs --with-openssl --with-gd --with-jpeg-dir=/opt/amp --with-png-dir=/opt/amp \
@rmcvey
rmcvey / gist:7283200
Created November 2, 2013 20:35
Example usage of extending the Base_Mongo class. Read more here: http://www.php.net/manual/en/class.mongocollection.php
<?php
class MessageStorage extends Base_Mongo
{
protected $_database = 'some_database';
// this attribute must be defined
protected $_table = 'some_table';
// this is a hook into the constructor, if you want to add your own constructor, make sure you call parent::__construct() first
public function init()
@rmcvey
rmcvey / counter.js
Last active August 29, 2015 14:00
counter style ajax transactions
var endpoints = ['/data/step1', '/data/step2', '/data/step3'];
var run_cnt = 0;
var success_cnt = 0;
function final_action(){
console.log('completed!');
}
function fail_action(){
console.log("something went wrong!");
@rmcvey
rmcvey / promise.js
Last active August 29, 2015 14:00
Promises-based AJAX transactions
var endpoints = ['/data/step1', '/data/step2', '/data/step3'];
// this will hold our promises
var promises = [];
$.each(endpoints, function(index, url){
// push the returned promise from $.get to our array
promises.push($.get(url));
})
// $.when takes a list of promises, we will use apply to pass an arbitrary number of arguments