Skip to content

Instantly share code, notes, and snippets.

@softwarespot
softwarespot / select_append.js
Created August 1, 2015 08:01
Append an option element to a select element
// Append an option element to a select element
var $input = $('select');
$('<option/>')
.prop('value', value)
.html(value)
.appendTo($input);
@softwarespot
softwarespot / undefined.js
Last active September 30, 2015 06:21
Funny JS oddity
var undefined = 'Undefined is now a string';
// Immediately-Invoked Function Expression (IIFE)
(function (undefined) {
console.log('Local undefined is: ' + (typeof undefined));
})(); // Don't pass anything, so undefined locally will be truly undefined
console.log('Global undefined: ' + (typeof undefined));
@softwarespot
softwarespot / squirrel_demo.html
Last active August 29, 2015 14:26
Squirrel.js form example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Squirrel.js form demo</title>
<!--Mobile Specific Metas-->
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
@softwarespot
softwarespot / jquery.ba-tinypubsub.js
Last active September 30, 2015 06:22 — forked from rwaldron/jquery.ba-tinypubsub.js
PubSub module in jQuery
/*
* jQuery Tiny Pub/Sub - v0.1 - 2015/08/07
* http://benalman.com/
*
* Original Copyright (c) 2010 'Cowboy' Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Made awesome by Rick Waldron, with additional ideas by Jeffrey Way and softwarespot
* URL: https://gist.github.com/rwaldron/705311
@softwarespot
softwarespot / pubsub.md
Last active September 13, 2015 17:09 — forked from learncodeacademy/pubsub.js
PubSub module in vanillaJS
@softwarespot
softwarespot / $.each-$.map.js
Last active September 30, 2015 06:24
Demo of $.each and $.map
// jQuery source outlines differences
const items = [1, 2, 3, 4, 5];
// MAP
// $.map() returns a new array
const array = $.map(items, function (item, index) { // item first then index
console.log(item);
@softwarespot
softwarespot / settings.json
Created August 9, 2015 16:21
Visual Studio Code settings
// Place your settings in this file to overwrite the default settings
{
// Controls the font family.
"editor.fontFamily": "Source Code Pro",
// When enabled, will trim trailing whitespace when you save a file.
"files.trimTrailingWhitespace": true,
// Don't spare curly brackets.
"javascript.validate.lint.curlyBracketsMustNotBeOmitted": "error",
@softwarespot
softwarespot / eventUtility.js
Last active October 24, 2017 06:45 — forked from justinwhall/eventUtility.js
JS | Cross Browsers Event Utility Object
var EventsUtility = {
addEvent: function (element, type, callback) {
if (typeof addEventListener !== 'undefined') {
element.addEventListener(type, callback, false);
} else if (typeof attachEvent !== 'undefined') {
element.attachEvent('on' + type, callback); // IE, legacy browser
} else {
element['on' + type] = callback;
}
},
@softwarespot
softwarespot / draggable.js
Last active January 18, 2016 19:18
Draggable plugin
/**
* Draggable module
*
* @link https://gist.github.com/yuanchuan/1330150
*
* Modified: 2015/08/12
* @author softwarespot
*/
(function draggableModule(document, $) {
// Plugin Logic
@softwarespot
softwarespot / min_max.c
Last active April 21, 2017 19:01
A very simple min and max example in C
#include <stdio.h>
int main(void) {
int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int i = 0;
int max = data[0];
int min = data[0];
// Obtain the size of the array by obtaining the number of bytes of the array divided by the size of the first element