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 / 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();
}
@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 / 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 / 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 / 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 / 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 / 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 / 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 / accordian.jade
Created September 23, 2014 15:21
A five panel Bootstrap accordion written in jade. NOTE: div id and href id must be unique from other panels and match one another. See #collapseOne div and href='#collapseOne' below.
#accordion.panel-group
.panel.panel-default.panelOne
.panel-heading
h4.panel-title
a(data-toggle='collapse', data-parent='#accordion', href='#collapseOne')
span.activityTitle#panelOneTitle
#collapseOne.panel-collapse.collapse.in
.panel-body
h4.resource#panelOneResource
@dacur
dacur / crypto.js
Created September 19, 2014 20:13
Using CryptoJS to encrypt strings, e.g., passwords is as easy as adding the following lines of code to your app.
//add to your index page
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
// add to your JS file, for instance, on a click 'submit' button
password = $('#password').val();
password = CryptoJS.MD5(password);