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 / iterate.js
Created October 7, 2014 13:45
Iterating over child elements to determine if an element does NOT have a certain class. Child element icons have a default class of 'opacity50' that makes them grey instead of black. When clicked, that class is removed, making the selected icon black. Uses Font Awesome icons.
function JournalScale(){
$('#journalScale').children('i').each(function(){
if(!$(this).hasClass('opacity50')){
_smileySelected = (this).id;
}
});
}
@dacur
dacur / sortJournals.js
Last active August 29, 2015 14:07
User uses dropbox to select a search term. Clicks button to initialize search. Any result that does not match will have class 'displayNone' applied to it. (Build function runs first, displays journals) ****OPTIONAL: call from on change instead of on click. When dropdown state changes, the function will be called. See code below.
function SortJournalsWho(){
_selectedWho = $('#journalWhoTagSort option:selected').val();
$('.journalWho').each(function(){
if($(this).html()!=_selectedWho){
$(this).parent().addClass('displayNone');
}
});
}
function BuildCompletedJournals(data){
@dacur
dacur / getValue.js
Created October 9, 2014 20:43
Get the value of a Div (from a row of Divs that were clicked) that was dynamically created. See notes in code below.
$('.catRow').on('click', function(){
var catEditing = $(this).html(); //All divs in row
var catName = $(catEditing).closest('.catName').text();
alert(catName);
})
For example, you are dynamically creating rows of data that are given from the DB.
Each row is clickable.
To find the Name (catName; i.e. 'category name') of the clicked row, use this code!
@dacur
dacur / child_element.js
Created October 24, 2014 17:36
Target child element in jQuery. Class '.fa-folder' is child of '#pleasantRT'. Removing opacity from child element.
$('#pleasantRT > .fa-folder').removeClass('opacity50');
@dacur
dacur / AWS_CORS_policy.txt
Last active August 29, 2015 14:08
Creating a DropZone for image uploads. Also sending a JavaScript global variable via the DropZone Headers to the controller. More Header info here: http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-headers
****** NOTHING TO CHANGE HERE, JUST COPY AND PASTE INTO AWS ***********
<?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 / steps.txt
Last active August 29, 2015 14:08
Steps for image uploads in a Rails application.
1. Create bucket in Amazon AWS/S3. Choose US Standard.
2. Add More Permissions => Grantee: Everyone; Check 'List' and 'Upload/Delete'.
3. Edit Bucket Policy. Edit CORS Configuration. See uploads.js gist for code.
******
4. Add dropzone.js file, get contents from dropzone website.
5. Add 'require dropzone' to application.js file.
6. Add uploads.js file to hold dropzone code. See uploads.js gist for code.
******
7. Add #primaryImage div to view. This will be the target for the dropzone.
8. Add 'process' method from uploads.js gist to controller. Add route for /process.
@dacur
dacur / index.js
Last active August 29, 2015 14:08
Adding text boxes dynamically on button click using '.append()'.
$('.fa-times').on('click', function(){
$(this).closest('li').remove();
});
@dacur
dacur / create_guid.js
Created November 5, 2014 14:24
Creating a random string/GUID. Used it to give a 'group name'/identifier to a set of values.
function CreateGuid() {
function _p8(s) {
var p = (Math.random().toString(16) + "000000000").substr(2, 8);
return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
}
return _p8() + _p8(true) + _p8(true) + _p8();
}
<?xml version='1.1' encoding='utf-8'?>
<!-- IOS -->
<!-- <widget id="J9EHJHT37L.org.ncfb" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0"> -->
<!-- ANDROID -->
<widget id="org.ncfb" version="1.1.0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0"> -->
<name>NCFB</name>
<description>
North Carolina Farm Bureau
All of your valuable NCFB benefits in the palm of your hand.
@dacur
dacur / months.js
Created November 25, 2014 15:28
Creating a header for each month when listing out data by date (descending order). Month header only prints once per month.
function BuildCompletedJournals(data){
var i = 0;
var html = '';
var exists;
var month = '';
var journal;
var date = '';
var months = [];