Skip to content

Instantly share code, notes, and snippets.

View michaelminter's full-sized avatar

Michael Minter michaelminter

View GitHub Profile
@michaelminter
michaelminter / checkbox_limit
Created October 12, 2011 18:03
Limit number of selected check boxes
<script type="text/javascript">
$(function() {
$('form').submit(function() {
if ($(':checkbox:checked').length > 3) {
alert('Only 3 checkboxes allowed.');
return false;
}
});
});
</script>
@michaelminter
michaelminter / export_csv.rb
Created November 16, 2011 17:05
Export CSV with Mongoid and FasterCSV
def export_inverts
require 'fastercsv'
inverts = Invert.all
filename = params[:action] + ".csv"
#this is required if you want this to work with IE
if request.env['HTTP_USER_AGENT'] =~ /msie/i
headers['Pragma'] = 'public'
headers["Content-type"] = "text/plain"
headers['Cache-Control'] = 'no-cache, must-revalidate, post-check=0, pre-check=0'
@michaelminter
michaelminter / sendgrid_model.rb
Created December 6, 2011 01:49
Sendgrid method in notifier model
class Notifier < ActionMailer::Base
include SendGrid
default :from => Rails.configuration.sendgrid.reply_to
sendgrid_enable :opentrack, :clicktrack, :ganalytics
sendgrid_category :testing
def user_updated(user)
@user = user
mail( :to => @user.email,
:subject => "Your information has been updated.") do |format|
@michaelminter
michaelminter / select_line.html.erb
Created January 19, 2012 20:30
Multiline select with view
<style typoe="text/css">
div#tasks_js_drop { margin-left:143px;width:650px; }
div#tasks_js_drop div { border:1px solid #CCCCCC;margin:5px 0;padding:5px;position:relative; }
div#tasks_js_drop div a img { position:absolute;top:3px;right:5px; }
</style>
<script type="text/javascript">
$(function() {
// Add newly selected tasks
$('#schedule_task_ids').change(function() {
@michaelminter
michaelminter / amazon-mysql.sh
Created February 8, 2012 20:27
Installing MySQL on EC2's Amazon Linux AMI
yum install mysql mysql-server mysql-libs
service mysqld start
chkconfig --levels 235 mysqld on
mysql_secure_installation
@michaelminter
michaelminter / jquery.current_url.js
Created February 24, 2012 18:58
Grab current URL with Javascript
var url = document.location.toString();
@michaelminter
michaelminter / flickr.php
Created July 22, 2012 20:05
Flickr API written in PHP
$api = 'your-32-byte-api-key-courtesy-Flickr';
$user_id = '33822702%40N08';
$per_page = 10;
$xml = 'http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key='.$api.'&user_id='.$user_id.'&per_page='.$per_page;
$flickr = simplexml_load_file($xml);
foreach($flickr->photos->photo as $p) {
echo '<a href="http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id'].'">';
echo '<img src="http://farm'.$p['farm'].'.static.flickr.com/'.$p['server'].'/'.$p['id'].'_'.$p['secret'].'_s.jpg">';
@michaelminter
michaelminter / check_count.js
Created August 4, 2012 08:16
Check for update count
setInterval( "checkObjectCount()", 10000 );
function checkObjectCount() {
var current_count = <%= @object_count %>;
$.ajax({
url: 'ajax/request_object_count',
success: function(data) {
if (data > current_count) {
$('#alert_container').show();
@michaelminter
michaelminter / java_console.md
Created September 10, 2012 15:35
Activate Java console on Mac OS X

When you need to debug a Java applet running on your website, there's only one way, and that's with the Java console. To access:

Applications > Utilities > Java Console

... and select 'Show console' with any other options you'd like to show up.

@michaelminter
michaelminter / index.html
Created September 20, 2012 01:14
Splash page template
<header class="main-header">
<hgroup class="main-headings">
<h1 class="main-heading">Fact: Better buttons increase app installs.</h1>
<h2 class="sub-heading">Thousands of people use Growify's appstore badges (free) and SMS app install buttons" (<a href="/pricing" class="header-link">see pricing</a>)</h2>
</hgroup>
<a href="/create-account" class="button button-blue button-large try-it-free">Get the code for your site »</a>
<p class="no-credit-card-required">No obligation.</p>
</header>
<section class="content">
<aside class="slider">