Skip to content

Instantly share code, notes, and snippets.

View erkattak's full-sized avatar

Erik Straub erkattak

View GitHub Profile
@erkattak
erkattak / hash.rb
Created January 11, 2012 15:08
flattening a multidimensional hash
ALLOWED_TYPES = {
'pdf' => ['application/pdf', 'application/x-download'],
'image' => ['image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'],
'text' => ['application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
'spreadsheet' => ['application/excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
}
ALLOWED_TYPES.map{ |g,s| s }.flatten # => ["application/pdf", "application/x-download", "image/jpg", "image/jpeg", "image/pjpeg", "image/png", "image/x-png", "image/gif", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]
@erkattak
erkattak / syntax_highlighting.py
Created December 6, 2011 15:53 — forked from JeanMertz/syntax_highlighting.py
Ruby on Rails syntax highlight switcher for Sublime Text 2
import sublime, sublime_plugin
import os
class DetectFileTypeCommand(sublime_plugin.EventListener):
""" Detects current file type if the file's extension isn't conclusive """
""" Modified for Ruby on Rails and Sublime Text 2 """
""" Original pastie here: http://pastie.org/private/kz8gtts0cjcvkec0d4quqa """
def on_load(self, view):
filename = view.file_name()
@erkattak
erkattak / add-business-pod-page.php
Created November 16, 2011 23:52
Add a business via publicForm
<div id="content">
<span class="breadcrumbs"><a href="<?php bloginfo('url'); ?>">Home</a> &raquo; <a href="<?php bloginfo('url'); ?>/businesses">Businesses</a> &raquo; Add a Listing</span>
<h2 class="title">Add a Business Listing</h2>
<div class="entry clearfloat">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Hoc est non modo cor non habere, sed ne palatum quidem. Cum audissem Antiochum, Brute, ut solebam, cum M. Sed ut iis bonis erigimur, quae expectamus, sic laetamur iis, quae recordamur. Sed ne, dum huic obsequor, vobis molestus sim. An hoc usque quaque, aliter in vita? Haec para/doca illi, nos admirabilia dicamus. Quod equidem non reprehendo;</p>
<?php
$pod = new Pod('businesses');
$fields = array('name','business_type','content','excerpt','www','address','city','state','zip','email','phone','facebook','twitter','slug'=>array('hidden'=>true));
$pod->publicForm($fields,'Submit Business Listing',get_bloginfo('url').'/businesses/thank-you');
?>
function checkbox_list ($data, $name = 'list', $parent = 0, &$label = null) {
if (!empty($data)) {
echo '<div class="categories sub">';
foreach ($data as $item) {
if (isset($item['children']) && !empty($item['children'])){
$label .= (isset($label)) ? ' ' . $item['name'].' &raquo;' : $item['name'].' &raquo;';
checkbox_list($item['children'], $name, $item['id'],$label);
}else{
echo (isset($label)) ? '<h3>'.$label.'</h3>' : false;
echo '<label for="'.$name.'_'.$item['id'].'"><input type="checkbox" name="'.$name.'[]" value="'.$item['id'].'" id="'.$name.'_'.$item['id'].'" />'.$item['name'].'</label>';
Array
(
[0] => Array
(
[id] => 14735
[name] => Biotechnology and Related Specialties
[displaytype] => default
[parent_id] => 0
[children] => Array
(
Array
(
[0] => Array
(
[id] => 14735
[name] => Biotechnology and Related Specialties
[displaytype] => default
[parent_id] => 0
[children] => Array
(
@erkattak
erkattak / MY_Router.php
Created June 17, 2011 05:10
Using nested controllers in CodeIgniter 2.0
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* MY_Router allows the existence of controllers and controller sub directories of the same name
*
* @author Erik Straub
*/
class MY_Router extends CI_Router {
function __construct(){
parent::__construct();
@erkattak
erkattak / SQL_Loop.php
Created June 9, 2011 13:40
Looping SQL results
<?php
// get your sql results, etc
$results = mysql_query('SELECT * FROM table');
?>
<form>
<fieldset>
<legend>Your Legend</legend>
<select name="editlist">
<?php while($row = mysql_fetch_result($results, MYSQL_ASSOC) : ?>
<option value="<?php echo $row['companyname']; ?>"><?php echo $row['companyname']; ?></option>
@erkattak
erkattak / NextGEN-Cover-Image.php
Created May 30, 2011 21:40
WordPress - Pull NextGEN Gallery Preview Image using Gallery ID
<?php
$gallery_id = 1; // Use the PODS column, custom post field or however you would get this ID
$results = $wpdb->get_results("SELECT ng.path, np.filename FROM wp_ngg_pictures np, wp_ngg_gallery ng WHERE np.galleryid=ng.gid AND np.galleryid=".$gallery_id." AND np.pid=ng.previewpic",ARRAY_A);
if(!empty($results[0]['path']) && !empty($results[0]['filename'])) :
$imgpath = $results[0]['path'].'/'.$results[0]['filename'];
endif;
@erkattak
erkattak / RegExTimeRange
Created April 28, 2011 18:16
RegEx for Time Range (1-5pm, 11:45am-5pm, 1 - 5:15pm, etc.)
\b((?:(?<!:)(?:1?[0-9])(?::(?<!\d)[0-5]\d)?(?:\s?[ap][m]?)?)(?:\s?-\s?)(?<=-|\s)(?:(?:1?[0-9])(?::(?<!\d)[0-5]\d)?(?:\s?[ap][m]?)))\b