Skip to content

Instantly share code, notes, and snippets.

View joshtronic's full-sized avatar
🐢
🐢 🐢 🐢

Josh Sherman joshtronic

🐢
🐢 🐢 🐢
View GitHub Profile
@joshtronic
joshtronic / gist:8640234
Last active January 4, 2016 15:19
Checks your unread message count on your Gmail account from the command line using OSX Keychain Access to store the credentials securely.
export KEYCHAIN_ITEM='email' && curl -u `security find-generic-password -s ${KEYCHAIN_ITEM} | grep 'acct' | cut -c 19- | tr -d '"' | tr -d '\n'`:`security find-generic-password -w -s ${KEYCHAIN_ITEM}` --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "$2\n" if /<(email)>(.*)<\/\1>/;' | wc -l | tr -d ' '
$('[data-plugin]').each(function(element)
{
switch ($(element).data('plugin'))
{
case 'tagsInput':
$(element).tagsInput({ width: 'auto' });
break;
}
});
<?php
$conditions = array('conditions' => array('revision_id' => $recipe_revision->record['id']));
$cache_key = 'RECIPE-' . $recipe_revision->record['id'] . '-';
$recipe_ingredient = new RecipeIngredient($conditions, $cache_key . 'INGREDIENTS');
$recipe_direction = new RecipeDirection($conditions, $cache_key . 'DIRECTIONS');
// Checks that all of the fields are present and not null
if (isset($_POST['username'], $_POST['email'], $_POST['password'])
&& !String::isEmpty($_POST['username'], $_POST['email'], $_POST['password']))
{
// Checks that the username is the correct format
if (strlen($_POST['username']) > 32)
{
$message = 'Usernames may not be more than 32 characters.';
}
elseif (!preg_match('/^[a-z0-9-]+$/i', $_POST['username']))
<?php
class user_create extends AnonymousModule
{
protected $post = array(
'username' => array(
'length:>:32' => 'Usernames may not be more than 32 characters.',
'regex:/[^a-z0-9-]+/i' => 'Usernames may only contain alphanumeric characters or dashes.',
'regex:/^(-.+|.+-)$/' => 'Usernames may not start or end with a dash.',
'regex:/-{2,}/' => 'Usernames may not have two or more dashes in a row.',
<?php
if (isset($_SERVER['HTTP_USER_AGENT'])
&& !String::isEmpty($_SERVER['HTTP_USER_AGENT'])
&& !preg_match('/(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg)/i', $_SERVER['HTTP_USER_AGENT']))
{
exit('EOF');
session_start();
}
@joshtronic
joshtronic / gist:4228026
Created December 6, 2012 20:25
PICKLES Transactions
<?php
$transaction = new Transaction();
$model1 = new Model1();
$model1->record['foo'] = 'bar';
$model1->queue();
$transaction->queue($model1);
<?php
/**
* Smarty State Drop Down for PICKLES
*
* PICKLES is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
$reward = new MerchantReward();
for ($i = 1; $i <= 50; $i += 5)
{
$reward->record['merchant_id'] = '1';
$reward->record['location_id'] = '1';
$reward->record['reward'] = 'This is a reward';
$reward->record['visits'] = $i;
$reward->queue();
}
<?php
/**
* Prepare Variables
*
* Processes the request variable and creates all the variables that the
* Controller needs to load the page.
*
* @param string $basename the requested page
* @return array the resulting variables