Skip to content

Instantly share code, notes, and snippets.

View teddyzetterlund's full-sized avatar

Teddy Zetterlund teddyzetterlund

View GitHub Profile
module DateTimeHelper
def format_date_range(date_range)
first = date_range.first
last = date_range.last
if same_day?(first, last)
"#{first.to_s(:month_day)}, #{first.year}"
elsif same_month?(first, last)
"#{first.to_s(:month_day)}-#{last.day}, #{last.year}"
else
"#{first.to_s(:month_day)}-#{last.to_s(:month_day)}, #{last.year}"
@bryanthompson
bryanthompson / cache_helper.rb
Created January 14, 2010 22:08
Simple fragment caching in sinatra
require 'sinatra/base'
class CacheHelper
module Sinatra
module Helpers
def cache(name, options = {}, &block)
if cache = read_fragment(name, options)
@_out_buf << cache
else
pos = @_out_buf.length
// Provides a device_scale class on iOS devices for scaling user
// interface elements relative to the current zoom factor.
//
// http://37signals.com/svn/posts/2407-device-scale-user-interface-elements-in-ios-mobile-safari
// Copyright (c) 2010 37signals.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@aalin
aalin / bellevue.rb
Created October 8, 2010 13:11
Prints the menu from restaurangbellevue.se
#!/usr/bin/env ruby
require 'iconv'
require 'open-uri'
class String
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
def colorize(color)
value = case color
when Symbol
@rmurphey
rmurphey / pubsub-demo.js
Created October 26, 2010 04:59
JS for pubsub screencast
/* traditional way */
(function($) {
$(document).ready(function() {
$('#searchForm').submit(function(e) {
var term = $.trim($(this).find('input[name="q"]').val());
if (!term) { return; }
$.getJSON(
@cowboy
cowboy / HEY-YOU.md
Last active October 25, 2024 15:29
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@jacortinas
jacortinas / github-challenge.html
Created February 11, 2011 05:33
A javascript solution to the github-challenge by integrum
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
</head>
<body>
<p id="loading_msg">Loading...</p>
<script type="text/javascript">
/* To being with, just in case the "$" is already taken in the global scope
@mralex
mralex / sinatra-memcacher.rb
Created May 5, 2011 05:41
Simple memcached helper for Sinatra.
require 'sinatra/base'
require 'memcached'
module Sinatra
module Memcacher
module Helpers
def cache(key, &block)
return block.call unless options.memcacher_enabled
begin
@140bytes
140bytes / LICENSE.txt
Created May 9, 2011 16:13
140byt.es -- Click ↑↑ fork ↑↑ to play!
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@jed
jed / LICENSE.txt
Created May 9, 2011 16:17 — forked from 140bytes/LICENSE.txt
communicate with jsonp
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE