Skip to content

Instantly share code, notes, and snippets.

View dacur's full-sized avatar

David Curtis dacur

  • Raleigh, North Carolina
View GitHub Profile
@dacur
dacur / controller.js
Created May 13, 2015 20:28
This code will allow you to upload images from an AngularJS app to Amazon AWS / S3. Be sure to find a secure way to store your Amazon secret keys! When the page loads, there is a button whose title is 'Choose Image'. When you click it, the file explorer opens. Choose an image. When the file explorer closes, this button's title becomes the name o…
function addLeagueCtrl($scope, $rootScope, $location, $http, DashboardService) {
AWS.config.update({accessKeyId: 'YOURACCESSID', secretAccessKey: 'YOURSECRETKETY'});
AWS.config.region = 'us-west-2';
var bucket = new AWS.S3({params: {Bucket: 'ezsportsadmin'}});
var fileChooser = document.getElementById('file-chooser');
var results = document.getElementById('results');
var imageURL = "";
$scope.fileChooser = fileChooser;
@dacur
dacur / main.js
Created May 4, 2015 12:39
JavaScript from an old project. Using Foursquare, Leaflet, and Twilio APIs.
var _map;
var _group;
var _userLocation;
$(document).ready(function(){
var url = location.pathname.substring(location.pathname.lastIndexOf('/')+1);
if (url == 'map') {
LoadMapPage();
}
@dacur
dacur / CORS_configuration
Last active January 14, 2020 09:30
Using AngularJS with Amazon AWS:S3 image uploads. Create new Amazon bucket. Under permissions, grant 'Everyone': List and Upload/Delete privileges. Be sure to set up Amazon bucket permissions below, as well. The image URL, when returned from Amazon, is being saved in $scope.imageURL. Now you can pass the image URL to your API from another functi…
Add under Permissions in your Amazon bucket:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
@dacur
dacur / raleighCrime.swift
Created March 26, 2015 22:30
Sample code from an iOS project using Swift and open data.
//
// ViewController.swift
// RaleighCrime
//
// Created by David Curtis on 3/15/15.
// Copyright (c) 2015 David Curtis. All rights reserved.
//
import UIKit
import Foundation
@dacur
dacur / sortarray.js
Created March 18, 2015 16:36
_solutionsContainer is an array of objects. This code sorts the objects in the array by their 'Order'. Order is an integer that was assigned to the objects when they were created (based on how many 'pros' the user selected; i.e., 7 pros checked meant the Order was 7). Note: listing 'b' first in the return statement means that they are listed hig…
_solutionsContainer = _solutionsContainer.sort(function(a,b) { return (b.Order) - (a.Order) });
@dacur
dacur / mapData.swift
Last active August 29, 2015 14:17
This gist uses MapKit to display a map on the user's screen (iOS). Then, one point is added to a map. When the button is clicked, another point is added to the map. The data is from Raleigh's open data on crime. This code is a work in progress. I wanted to see if I could get the data back, and then on a button click, add it to the map. As you ca…
//
// ViewController.swift
// RaleighCrime
//
// Created by David Curtis on 3/15/15.
// Copyright (c) 2015 David Curtis. All rights reserved.
//
import UIKit
import Foundation
@dacur
dacur / application.html.erb
Created February 28, 2015 16:23
This is a sample application.html.erb file that adds bootstrap styling to devise alerts. It uses green and red coloring, and adds an 'x' button so that the messages can be dismissed.
<!DOCTYPE html>
<html>
<head>
<title>YOUR TITLE HERE</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
@dacur
dacur / devise_helper.rb
Created February 28, 2015 16:21
This helper file will add bootstrap styling to your devise error messages, and will make them more readable. Add this file to your helper files folder.
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t('errors.messages.not_saved', count: resource.errors.count, resource: resource.class.model_name.human.downcase)
html = <<-HTML
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
@dacur
dacur / checkboxes.js
Created February 20, 2015 20:07
Checking if 'fancy' checkboxes are checked, and reseting them to unchecked.
$('#howDidIFeelCheckboxes').find('input').each(function(){
if($(this).is(':checked')){
$(this).attr('checked', false);
}
});
@dacur
dacur / countItems.js
Created February 9, 2015 17:03
Every time a filter is applied/clicked, check to see if any items are displayed on the page. If not, display the message "Your search did not return any results. Please try again.". The message is hidden by default. The searches are fired on the click of a dropdown item. This function is called from each search function.
function DoesFilterReturnZeroItems(){
var hiddenItems = 0;
var allItems = 0;
$('#closetItems').find('.closetWrapper').each(function(){
if($(this).hasClass('displaynone')){
hiddenItems++;
}
allItems++;
});
if(allItems==hiddenItems){