Skip to content

Instantly share code, notes, and snippets.

View jimjeffers's full-sized avatar

Jim Jeffers jimjeffers

View GitHub Profile
class ApplicationController < ActionController::Base
before_filter unless: :devise_controller? do
resource = controller_name.singularize.to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end
end
@jimjeffers
jimjeffers / landscape-compass-direction.m
Last active August 29, 2015 13:56
Get the expected reading from the iPhone's compass when holding the phone in either landscape orientation.
- (void)locationManager:(CLLocationManager*)manager
didUpdateHeading:(CLHeading*)newHeading {
// If the accuracy is valid, process the event.
if (newHeading.headingAccuracy > 0) {
/**
* The orientation affects the compass. We need to actually
* base the orientation off of the top of the iPhone. Think
* of the direction the phone is facing when you hold it right
/**
* This example programatically generates a series of UIViews each
* 244x2000 and stacks them vertically inside of a scroll view.
* To do this we dynamically build a dictionary as we generate
* the views and simultaneously build an array of height
* constraints. Once the loop has completed we combine all of the
* constraints into a single string and apply the last constraint
* to the scrollview.
*
* This example assumes you're working in a UIViewController with
@jimjeffers
jimjeffers / get_direction.js
Created November 20, 2013 20:15
Get direction from bearing.
//
// Get direction
//
this.getDirectionFromBearing = function(bearing) {
if (bearing > 330 || bearing <= 15) {
return "N";
} else if (bearing > 15 || bearing <= 60) {
return "NE";
} else if (bearing > 60 || bearing <= 105) {
return "E";
@jimjeffers
jimjeffers / staging.log
Created October 29, 2013 20:49
Staging log of carrier wave bug.
Started POST "/admin/photos/7/approve" for 199.223.122.34 at 2013-10-29 20:46:18 +0000
2013-10-29T20:46:18.589054+00:00 app[web.1]: Processing by Admin::PhotosController#approve as */*
2013-10-29T20:46:18.589054+00:00 app[web.1]: Parameters: {"id"=>"7"}
2013-10-29T20:46:18.598598+00:00 app[web.1]: Photo Load (4.2ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = $1 LIMIT 1 [["id", "7"]]
2013-10-29T20:46:18.603564+00:00 app[web.1]: (4.6ms) BEGIN
2013-10-29T20:46:18.610299+00:00 app[web.1]: Photo Load (3.8ms) SELECT "photos".* FROM "photos" WHERE "photos"."id" = $1 LIMIT 1 [["id", 7]]
2013-10-29T20:46:18.613560+00:00 app[web.1]: (2.3ms) UPDATE "photos" SET "approved" = 't', "image" = '0289da71-14cd-46c1-a42c-feff92ac0303/Screen%2520Shot%25202013%252010%252029%2520at%25201.44.20%2520PM.png', "updated_at" = '2013-10-29 20:46:18.610428' WHERE "photos"."id" = 7
@jimjeffers
jimjeffers / carrier_wave_direct_form.html.erb
Created October 29, 2013 20:31
Form used to create a photo w/ Carrier Wave Direct.
<!-- Form Container Start -->
<div class="form-container">
<% if params[:key].nil? %>
<%= direct_upload_form_for @uploader, html: {:class => "form"} do |f| %>
<p class="field">
<label>Select a photo to upload:</label><br>
<%= f.file_field :image %>
</p>
<p class="field">
@jimjeffers
jimjeffers / touchEventDropDown.html
Created August 22, 2012 23:00
Basic drop down via touch events. Doesn't cover everything just a simple example.
<!DOCTYPE html>
<html>
<head>
<style type="text/css" media="screen">
.pressed {
background: #f00;
}
.js-dropDown {
display: none;
@jimjeffers
jimjeffers / CAMMFileUpload.m
Created July 23, 2012 15:33
File upload process for CAMM resizing image, utilizing parse, and communicating to web view.
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Hide the image picker.
[picker dismissModalViewControllerAnimated:YES];
// Reference the image from the picker.
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Use the size of the image to calculate its aspect ratio.
float aspectRatio = image.size.width/image.size.height;
@jimjeffers
jimjeffers / JugglingShelvesViewController.m
Created May 24, 2012 22:54
Figuring out how to juggle UIImageViews as a UIScrollview scrolls.
- (void)viewDidLoad
{
[super viewDidLoad];
// We'll want the controller to become the scrollView's delegate
// in order to respond to changes in the content offset position.
shelfScrollView.delegate = self;
// We'll generate an array of image views to serve as the shelf
// background. These shelves will reposition as they scroll out
// of the viewport.
background-image: -webkit-radial-gradient(50% 50%, circle closest-side, #2249e1 0%, #1d1e5e 100%);
background-image: radial-gradient(50% 50%, circle closest-side, #2249e1 0%, #1d1e5e 100%);