Skip to content

Instantly share code, notes, and snippets.

View jcutrell's full-sized avatar

Jonathan Cutrell jcutrell

View GitHub Profile
<!-- Classdate form -->
<% if (params[:classdate] and params[:classdate][:course_id]) or @classdate.id %>
<%= nested_form_for(@classdate) do |f| %>
<% if @classdate.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@classdate.errors.count, "error") %> prohibited this classdate from being saved:</h2>
<ul>
<% @classdate.errors.full_messages.each do |msg| %>
@jcutrell
jcutrell / gist:7046200
Created October 18, 2013 18:47
The goal of the query is to select all users who do not have assignments within a range. The range is defined on the assignment model, so this would be in assignment.rb in a rails project Startdatetime and enddatetime are attributes on the Assignment model.
User.joins(:assignments).where.not("(assignments.startdatetime > ? AND assignments.startdatetime < ?) OR (assignments.enddatetime < ? AND assignments.enddatetime > ?)", startdatetime, enddatetime, startdatetime, enddatetime)
# This would be fine, except it does not include users who do not have assignments at all.
@jcutrell
jcutrell / gist:5887473
Created June 28, 2013 19:40
Named media queries with .lt and .gt classes
// named media queries - http://blog.scur.pl/2012/06/variable-media-queries-less-css/
@highdensity: ~"only screen and (-webkit-min-device-pixel-ratio: 1.5)",
~"only screen and (min--moz-device-pixel-ratio: 1.5)",
~"only screen and (-o-min-device-pixel-ratio: 3/2)",
~"only screen and (min-device-pixel-ratio: 1.5)";
@600: ~"only screen and (min-width: 600px)";
@800: ~"only screen and (min-width: 800px)";
@1000: ~"only screen and (min-width: 1000px)";
@1200: ~"only screen and (min-width: 1200px)";
@jcutrell
jcutrell / cacher.php
Created April 14, 2013 23:56
Simple PHP caching function
<?php
$handle = opendir('_cache/');
while (false !== ($entry = readdir($handle))) {
if (strlen($entry) > 2){
$a = explode(".", $entry);
$a = explode("_", $a[0]);
$tstamp = intval($a[1]);
$t = time();
if ($t > ($tstamp + 12)){
// do the call, rewrite the timestamp
@jcutrell
jcutrell / index.html
Created February 8, 2013 21:06
A CodePen by Jonathan Cutrell. Where's Waldo? - A little bit of webkit filter exploration, and a few little tricks here and there.
<div id="imageholder">
<img src="http://3.bp.blogspot.com/-JlYXI_mJn7U/UFIJ7_8iLJI/AAAAAAAAAWY/ClZoftC59Uc/s1600/TheGobblingGluttons.jpg">
<div id="glass"></div>
</div>
// From the 140bytes wishlist here: https://github.com/jed/140bytes/wiki/Wishlist
// TASK:
// Create a function which can create a DOM structure from this:
//
domBuilder(
[/HTML/],
[/HEAD/],
[/TITLE/],
"Wouldn't this be cool?",
[],
@jcutrell
jcutrell / index.html
Created August 26, 2012 19:06
Article About The Fridge
<doctype html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container">
<h1>The Fridge: A Startup Cultural Catalyst</h1>
<p>At Whiteboard, we are about culture. We're about family. We're about living <em>with</em> one another, as opposed to simply beside one another. For that reason, we recently took some time to create an internal tool.</p>
@jcutrell
jcutrell / gist:3144098
Created July 19, 2012 13:57
Centered text with letter-spacing fix
// requires jQuery
$("h2").each(function(){
var h2 = $(this);
var t = h2.text();
var last = t.split("")[t.length-1];
var newtext = t.substring(0,t.length-1) + "<span style='letter-spacing:0px;'>" + last + "</span>";
h2.html(newtext);
});
@jcutrell
jcutrell / gist:2881523
Created June 6, 2012 12:13
Relative Time (for Twitter)
// $.relativeTime - returns a string that tells how long ago the passed in string happened. For Twitter.
$.relativeTime = function(dateString) {
var rightNow = new Date();
var then = new Date(dateString);
if ($.browser.msie) {
// IE can't parse these crazy Ruby dates
then = Date.parse(dateString.replace(/( \+)/, ' UTC$1'));
}
@jcutrell
jcutrell / uniqrand.js
Last active October 4, 2015 21:38
Unique Random Number
function uniqRand(notThis, range){
var maybe = Math.floor(Math.random() * range);
if (maybe !== notThis){
return maybe;
} else {
return uniqRand(notThis, range);
}
}