Skip to content

Instantly share code, notes, and snippets.

View sgentile's full-sized avatar

Steve Gentile sgentile

  • Mile Two
  • Dayton, Ohio
View GitHub Profile
@sgentile
sgentile / Basic Javascript Callback
Created May 13, 2011 14:28
Basic Javascript Callback
<!-- This demonstrates a simple javascript callback -->
<div id="now">0</div>
<input type="button" id="goBtn" value="Go" />
<br/>
<div id="result">Let's go!</div>
<script>
var result = document.getElementById('result');
function animate(element, callback){
@sgentile
sgentile / KnockoutJsHistory
Created May 13, 2011 14:32
KnockoutJS with History
<!doctype html>
<html lang="en">
<head>
<title>knockout binding test</title>
<style type="text/css">
#sidebar { float: left; width: 15em; }
#details { float: left; }
#sidebar li { list-style: none; }
#sidebar a { list-style: none; background-color: silver; width: 8em; margin-bottom: 0.5em; padding: 0.5em; display:block; }
#sidebar a.selected { background-color: Navy; color: white; }
@sgentile
sgentile / jsmodule.js
Created August 11, 2011 11:37
Javascript Module Pattern
<script type="text/javascript">
//from book 'Javascript the Good parts' p.58
//The methods do not make use of this or that.
//As a result, there is no way to com- promise the seqer.
//It isn’t possible to get or change the prefix or seq
//except as per- mitted by the methods. The seqer object
//is mutable, so the methods could be replaced, but
//that still does not give access to its secrets.
//seqer is simply a collection of functions, and
@sgentile
sgentile / jqueryfilter.js
Created September 10, 2011 05:14
find and not find filter
$(".navigatorModifierSearch").live('keyup', function (event) {
var $navigationelementsContainer = $(this).parent().parent().find(".navigationelementsContainer");
var searchTerm = $(this).val();
if (searchTerm.length > 0) {
$navigationelementsContainer.find('div[data-name*="' + searchTerm.toUpperCase() + '"]').removeClass("hideNavElement");
$navigationelementsContainer.children().not('div[data-name*="' + searchTerm.toUpperCase() + '"]').addClass("hideNavElement");
} else {
//make sure all are showing
$navigationelementsContainer.children().removeClass("hideNavElement");
@sgentile
sgentile / Extend
Created December 12, 2011 19:48
Extending Object
function Foo(options) {
if (!(this instanceof Foo)) {
return new Foo(options);
}
options = options || {};
$.extend(this, {
Id: 0,
Bar: null,
Bars: []
}, options);
@sgentile
sgentile / gist:1777385
Created February 9, 2012 04:47
Coffeescript static property and method
class Person
@test: (input) ->
return input
@staticProperty : 10
@get: ->
return {name:'Steve'}
nonStatic: ->
return "non static"
console.log Person.test 'Hello World'
@sgentile
sgentile / coffeescriptNodeModule
Created July 31, 2012 01:48
Calling a Module with Coffeescript
#helloWorld.coffee file
# Node Module
run = ->
console.log 'This is example node module'
exports.run = run
# Calling from another file, ie. app.coffee
@sgentile
sgentile / python_map_reduce
Last active December 20, 2015 05:29
simple python map and reduce
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
people = []
people.append(Person("Steve", 43))
people.append(Person("Tyler", 8))
print map(lambda x: x.age, people) # [43,8]
@sgentile
sgentile / ruby_map_reduce
Last active December 20, 2015 05:39
Simple ruby map and reduce example
people = [{name:'Steve', age:43},{name:'Tyler', age:8}]
puts people.reduce(0) {|sum, value| sum + value[:age] } # 51
puts people.map {|n| n[:age]} # 43, 8
learn more! http://ruby-doc.org/core-2.0/Enumerable.html
@sgentile
sgentile / Gruntfile.js
Last active August 29, 2015 14:00
Example of how I used Grunt with Durandal
module.exports = function (grunt) {
grunt.initConfig({
clean: ['css/style.min.css', 'app/main-built.js'],
concat: {
css: {
src: ['css/style.css'],
dest: 'css/temp.css'
}
},
cssmin: {