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 / guid.js
Created February 5, 2015 21:36
Create a unique GUID. I sometimes use these when I need a unique value; for instance, when I need to add a unique ID to a DIV.
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();
}
// to create a GUID, just call it like this:
// var id = CreateGuid();
@dacur
dacur / pushArray.js
Created February 3, 2015 15:14
Loop through a set of checkboxes. If checked, push into an array.
var inputID = "";
$('#howDidIFeelCheckboxes').find('input').each(function(){
if($(this).is(':checked')){
inputID = $(this).attr('id');
// alert(id);
_howDidIFeelPopup.push(inputID);
}
});
@dacur
dacur / password.js
Last active August 29, 2015 14:13
Password validation using regular expressions. Returns an error message based on what is missing/wrong with the user's password (or returns "ok"). Password must contain at least one letter and one number, must be between 6 and 50 characters in length, and may contain certain special characters (such as !, #, &, etc.).
function ValidatePassword(str){
if (str.length < 6) {
return("Password is too short. Must be at least 6 characters.");
} else if (str.length > 50) {
return("Password is too long. Must be no more than 50 characers.");
} else if (str.search(/\d/) == -1) {
return("Password must contain at least one number.");
} else if (str.search(/[a-zA-Z]/) == -1) {
return("Password must contain at least one letter.");
@dacur
dacur / loginsignup.swift
Last active August 29, 2015 14:13
A generic signup / login form for an iOS app written in Swift. NOTE: This uses Parse for user management. Put your Parse credentials in your AppDelegate.swift file.
import UIKit
class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
var signupActive = true
var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
func displayAlert(title: String, error:String){
@dacur
dacur / click
Last active August 29, 2015 14:13
Selecting a list item from a 'ddl' type dropdown list. You cannot use .change(). Can then fire a 'sort' function to sort on the selected 'li'.
$(".occassionRow").click ->
alert "changed"
return
@dacur
dacur / keyboard
Created January 7, 2015 15:27
How to make UITextField move up when keyboard is present.
http://ios-blog.co.uk/tutorials/how-to-make-uitextfield-move-up-when-keyboard-is-present/
@dacur
dacur / placeholder.less
Created December 29, 2014 17:59
Change placeholder text color for text areas.
::-webkit-input-placeholder {
color: @grey !important;
}
:-moz-placeholder {
color: @grey !important;
}
::-moz-placeholder {
color: @grey !important;
}
:-ms-input-placeholder {
@dacur
dacur / animate.js
Created November 26, 2014 17:57
Animate a form: drops into view from the top of the page when 'add' button is clicked. When 'save' is clicked, it animates up and out of view again. No extra JS library needed.
function ShowAssertiveForm(){
$('.assertiveFormSlider').animate({
top: '400px'
}, 600);
}
function HideAssertiveForm(){
$('.assertiveFormSlider').animate({
top: '-400px'
}, 400);
@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 = [];
<?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.