Skip to content

Instantly share code, notes, and snippets.

@greggb
greggb / div swap - time
Created December 12, 2011 18:39
Swap two divs if between two times on two days
$(document).ready(function(){
$("#maint").hide();
var d=new Date();
hour = d.getHours();
today = d.getDay();
if((today===5 && hour >= 20)||(today===6 && hour < 6)){
$("#apply").hide();
$("#maint").show();
}
});
@greggb
greggb / fizzbuzz.js
Created January 19, 2012 16:55
FizzBuzz
var count = prompt("number?");
var fb = function(n){
for (i=1;i<=n;i++){
if(i%3===0){
if(i%5===0){
console.log("fizzbuzz");
}
else{
console.log("fizz");
}
@greggb
greggb / getViewportSize.js
Created April 17, 2012 14:06 — forked from mrmartineau/getViewportSize.js
Reliably get viewport dimensions in JS
/*!
An experiment in getting accurate visible viewport dimensions across devices
(c) 2012 Scott Jehl.
MIT/GPLv2 Licence
*/
function viewportSize(){
var test = document.createElement( "div" );
test.style.cssText = "position: fixed;top: 0;left: 0;bottom: 0;right: 0;";
@greggb
greggb / simple-slide.js
Created April 24, 2012 02:27
Create a slideshow of list items
$("body").on("click", "#next, #prev", function(e){
var visibleslide = $("ul").find(".is-visible");
var totalslides = $("ul li").length-1;
$(visibleslide).removeClass("is-visible");
e.preventDefault();
if ( $(this).attr("id")==="next" ) {
if ( $(visibleslide).index()===totalslides ) {
$("li:eq(0)").addClass("is-visible");
@greggb
greggb / launch_sublime_from_terminal.markdown
Created May 5, 2012 19:50 — forked from artero/launch_sublime_from_terminal.markdown
Launch Sublime Text 2 from the Mac OS X Terminal

Launch Sublime Text 2 from the Mac OS X Terminal

Sublime Text 2 ships with a CLI called subl (why not "sublime", go figure). This utility is hidden in the following folder (assuming you installed Sublime in /Applications like normal folk. If this following line opens Sublime Text for you, then bingo, you're ready.

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

You can find more (official) details about subl here: http://www.sublimetext.com/docs/2/osx_command_line.html

Installation

@greggb
greggb / crunch-withicon.zsh-theme
Created May 5, 2012 20:06
Crunch ZSH theme with icon
# CRUNCH - created from Steve Eley's cat waxing.
# Initially hacked from the Dallas theme. Thanks, Dallas Reedy.
#
# This theme assumes you do most of your oh-my-zsh'ed "colorful" work at a single machine,
# and eschews the standard space-consuming user and hostname info. Instead, only the
# things that vary in my own workflow are shown:
#
# * The time (not the date)
# * The RVM version and gemset (omitting the 'ruby' name if it's MRI)
# * The current directory
@greggb
greggb / sc-dl.js
Created May 29, 2012 17:16 — forked from erikvold/sc-dl.js
Bookmarklet that generates download link for a Soundcloud upload
(function(d) {
var dl = d.createElement('a');
dl.innerText = 'Download MP3';
dl.href = "http://media.soundcloud.com/stream/"+d.querySelector('#main-content-inner img[class=waveform]').src.match(/\.com\/(.+)\_/)[1];
dl.download = d.querySelector('em').innerText+".mp3";
d.querySelector('.primary').appendChild(dl);
dl.style.marginLeft = '10px';
dl.style.color = 'red';
dl.style.fontWeight = 700;
})(document);
@greggb
greggb / gist:3830554
Created October 3, 2012 23:29
Jinja Loop Over Subset
{% for item in all_items %}
{% if loop.index <= n %}
{{ item }}
{% endif %}
{% endfor %}
@greggb
greggb / index.html
Created November 15, 2012 18:04 — forked from anonymous/index.html
A CodePen by Fabrice Weinberg. position:sticky; polyfill/shim - Just tried to make a polyfill for position:sticky; Wrote a Modernizr test. Tested in Chrome 23 (supported), Safari 6 and Firefox 14/15 doesn't work on iOS.
<div id="shim"></div>
<div class="textHolder"><h1>Try to scroll</h1><div class="sticky">Java script</div>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</div><div class="textHolde
define([
"use!underscore",
"use!handlebars",
"moment"
],
function(
_, Handlebars, Moment
) {