Skip to content

Instantly share code, notes, and snippets.

View benhowdle89's full-sized avatar

Ben Howdle benhowdle89

View GitHub Profile
@benhowdle89
benhowdle89 / gist:7083705
Created October 21, 2013 13:15
How http://healthcare.gov checks if the device is mobile...
// checks screen size
var isMobile = {
any: function() {
return($(window).width()<=599);
// nexus7 width is 600 (window.innerWidth)
// this will not run any reformatting for the phone layout on nexus
}
};
@benhowdle89
benhowdle89 / gist:7097460
Created October 22, 2013 09:04
Makes the keyboard disappear on mobiles with JS
var activeElement = document.activeElement;
if(activeElement){
activeElement.blur();
}
@benhowdle89
benhowdle89 / gist:7584827
Last active February 7, 2024 11:30
A todo app you can run from the browser's address bar. No persistence (boo localstorage security risk). Made by @benhowdle.
data:text/html,<div class="wrap"> <h1>Todo<span>, no fuss lists</span></h1> <input placeholder="Add a todo" type="text" id="item" /> <button id="go">Save</button> <span class="help">* tap to delete</span> <ul id="tudu_list"> </ul> </div><script type="text/javascript">var tudu_list = document.getElementById('tudu_list'); var item = document.getElementById('item'); var new_li; var new_obj = {}; function prependElement(parentID,child) { parent=parentID; parent.insertBefore(child,parent.childNodes[0]); } function remove(element){ element.parentNode.removeChild(element); } function deleteItem(){ var answer = confirm('Sure you want to remove this?'); if(answer){ var deleteId = this.getAttribute('rel'); remove(this); } } function addItem(){ if(item.value !== ''){ new_li = document.createElement('li'); new_li.innerHTML = item.value; prependElement(tudu_list, new_li); new_li.onclick = deleteItem; item.value = ''; } } function callAdd(e){ if(event.keyCode == 13){ addItem(); } } item.onkeyup = function(e){ callAdd(e) };
@benhowdle89
benhowdle89 / 0_reuse_code.js
Created February 1, 2014 20:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@benhowdle89
benhowdle89 / gist:9533185
Created March 13, 2014 17:41
Gulp + Watchify + Browserify + Handlebars + LiveReload
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var livereload = require('gulp-livereload');
var hbsfy = require("hbsfy").configure({
extensions: ["html"]
});
gulp.task('watch', function() {
NSInteger count = [timelineData count];
for (NSInteger index = (count - 1); index >= 0; index--) {
NSMutableDictionary *tweet = timelineData[index];
if (tweet[@"retweeted_status"]) {
[timelineData removeObjectAtIndex:index];
} else {
NSMutableDictionary *userObject = [tweet[@"user"] mutableCopy];
int fav_count = tweet[@"favorite_count"];
int rt_count = tweet[@"retweet_count"];
int follower_count = userObject[@"followers_count"];
Had a similar question a few weeks ago, so might as well forward you that!
http://addyosmani.com/resources/essentialjsdesignpatterns/book/
http://shop.oreilly.com/product/0636920025245.do
http://shop.oreilly.com/product/0636920018421.do
http://shop.oreilly.com/product/9780596806767.do
@benhowdle89
benhowdle89 / index.js
Created June 12, 2014 12:45
requirebin sketch
var $ = require('jquery');
$('body').css('background-color', 'red');
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var livereload = require('gulp-livereload');
var hbsfy = require("hbsfy").configure({
extensions: ["html"]
});
gulp.task('scripts', function() {
@benhowdle89
benhowdle89 / base-view.js
Created July 15, 2014 13:49
CommonJS Backbone inheritence
var Backbone = require('backbone');
var $ = require('jquery');
var Handlebars = require('handlebars');
var HandlebarsHelpers = require('base/utils/template-helpers');
var templateCache = require('base/utils/template-cache');
module.exports = Backbone.View.extend({
initialize: function(options) {
this.templates = templateCache.get();