Skip to content

Instantly share code, notes, and snippets.

View timhudson's full-sized avatar

Tim Hudson timhudson

View GitHub Profile
@timhudson
timhudson / yahoo-embed.html
Created October 28, 2012 06:04
Most minimal yahoo embed (Electric City)
<iframe frameborder="0" width="576" height="324" src="http://d.yimg.com/nl/cbe/electriccity/player.html#vid=29363409"></iframe>
@timhudson
timhudson / iceberg.css
Created December 3, 2012 00:19
Pygments Iceberg
.highlight .hll { background-color: #ffffcc }
.highlight { background: #323b3d; color: #bdd6db; background-color: #323b3d }
.highlight .c { color: #537178; background-color: #323b3d } /* Comment */
.highlight .err { color: #bdd6db; background-color: #323b3d } /* Error */
.highlight .g { color: #bdd6db; background-color: #323b3d } /* Generic */
.highlight .k { color: #b1e2f2; background-color: #323b3d } /* Keyword */
.highlight .l { color: #bdd6db; background-color: #323b3d } /* Literal */
.highlight .n { color: #bdd6db; background-color: #323b3d } /* Name */
.highlight .o { color: #bdd6db; background-color: #323b3d } /* Operator */
.highlight .x { color: #bdd6db; background-color: #323b3d } /* Other */
@timhudson
timhudson / responsive_grid.markdown
Created December 13, 2012 05:50
Getting consistent aspect ratios in a responsive grid

Padding-bottom: who knew you had it in you?

I've built many responsive layouts in the last couple years and my achilles' heel has always been a fluid grid of (n) squares, or anything with a fixed aspect ratio.

Say you want a grid of movie posters to all line up evenly. You could start with setting up the x-axis:

.grid-item {
@timhudson
timhudson / _app.js
Last active December 12, 2015 04:48
Mounting sub apps with express
var express = require('express'),
app = express();
var api = require('./api.js'),
embeds = require('./sub-app-2.js');
app.use(api);
app.use(embeds);
app.listen(3000);

Here is an example of using some helper methods to help manage boilerplate view code. This baseInitialize helper basically wraps the existing initialize method and runs some boilerplate code first.

// Global helper object
var helpers = {
  
  // Example helper
  // This method will wrap any existing initialize method
  // and run some boilerplate first
 baseInitialize: function(view) {
@timhudson
timhudson / express.js
Last active January 17, 2019 11:34
Internal routing within a single node process using express
var request = require('request')
, express = require('express')
, app = express()
var port = process.env.PORT || 5000
app.get('/api', function(req, res) {
res.send('I am from the API')
})
@timhudson
timhudson / app-code.js
Last active October 30, 2020 12:28
Scroll start/stop events using jQuery
$(function() {
$(document).on('scrollstart', function() {
console.log('scroll started')
})
$(document).on('scrollend', function() {
console.log('scroll ended')
})
@timhudson
timhudson / pre-save-update.js
Last active July 3, 2020 08:58
Update the `lastUpdated` field every time a mongoose model is saved
var schema = mongoose.Schema({
lastUpdated: {type: Date, 'default': Date.now}
})
schema.pre('save', function(next) {
this.lastUpdated = Date.now()
next()
})
Watchlists.View = Backbone.Marionette.CompositeView.extend({
template: Backbone.Marionette.TemplateCache.get('#watchlists-view'),
itemView: Watchlists.TableItemView,
itemViewContainer: 'tbody',
events: {
'submit .add-form': 'addWatchlist'
},
var Model = Backbone.SubCollectionModel.extend({
collectionAttribute: 'dogs',
collectionToJSON: function(collection) {
return collection.pluck('name')
}
})
var model = new Model({
name: 'example',
dogs: [