Skip to content

Instantly share code, notes, and snippets.

View jcutrell's full-sized avatar

Jonathan Cutrell jcutrell

View GitHub Profile
@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 / 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 / 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.
<!-- 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| %>
class ClassRegistrationsController < InheritedResources::Base
before_filter :authenticate_user!
def permitted_params
params.permit(:class_registration => [
:person_id, :classdate_id,
:document_assignments_attributes => [
:uploaded_document_id,
:uploaded_document => [
:document, :owner_type, :owner_id
// Examples for using socat (and filan)
//"$" means normal user, "#" requires privileges, "//" starts a comment
///////////////////////////////////////////////////////////////////////////////
// similar to netcat
// connect to 10.1.1.1 on port 80 and relay to and from stdio
class StripeTransaction < ActiveRecord::Base
has_many :line_items
accepts_nested_attributes_for :line_items
belongs_to :user
belongs_to :stripe_card
end
@jcutrell
jcutrell / getDataPartAtOffset.m
Created November 3, 2013 18:31
Translating Objective-C to RubyMotion code
- (NSData *)getDataPartAtOffset:(NSInteger)offset {
__block NSData *chunkData = nil;
if (fileAsset_){
static const NSUInteger BufferSize = PART_SIZE; // 5 MB chunk
ALAssetRepresentation *rep = [fileAsset_ defaultRepresentation];
uint8_t *buffer = calloc(BufferSize, sizeof(*buffer));
NSUInteger bytesRead = 0;
NSError *error = nil;
@try
@jcutrell
jcutrell / uploader.rb
Created November 6, 2013 01:36
ALAsset reading data for upload
def assets_library
@_assets_library ||= ALAssetsLibrary.alloc.init
end
@foo.clips.each_with_index do |clip,i|
# clip[1][:reference_url] refers to a video file chosen via BW::Device.camera.any.picture(media_types: [:movie]) do |result|
asset_url = clip[1][:reference_url]
assets_library.assetForURL(asset_url, resultBlock: lambda { |asset|
selectedAsset = asset
byteArraySize = selectedAsset.defaultRepresentation.size
@clip_object.clips.each_with_index do |clip, i|
# puts clip[:video][:media_url]
gcdq = Dispatch::Queue.concurrent(:high)
gcdq.async {
# por = S3PutObjectRequest.alloc.initWithKey(clip[:aws_path], inBucket:"southtree_dvds")
# por.contentType = "video/mp4"
# por.filename = clip[:video][:media_url].to_s
asset_url = clip[:video][:reference_url]
assets_library.assetForURL(asset_url, resultBlock: lambda { |asset|
# clip[:raw_data] = rawData