Skip to content

Instantly share code, notes, and snippets.

@kolber
kolber / index.html
Created August 20, 2010 06:11 — forked from rails/gist:58761
// Ruby strftime: %b %d, %Y %H:%M:%S GMT
time_ago_in_words = function(from, to) {
var to = to ? new Date(to) : new Date,
from = new Date(from);
var seconds = ((to - from) / 1000),
minutes = (seconds / 60);
if (minutes == 0) return 'less than a minute ago';
server.bind = "0.0.0.0"
server.port = 3000
server.document-root = CWD
server.dir-listing = "enable"
accesslog.use-syslog = "disabled"
accesslog.filename = "/var/log/lighttpd/access.log"
index-file.names = ( "index.html" )
mimetype.assign = (
".css" => "text/css",
/*
Delay function call by a specified time
---------------------------------------------
If the method is called again before the delay is up, reset the delay.
An optional id can be passed to prevent timeout collisions.
*/
Function.prototype.sleep = function(ms, id) {
var balanced_parens = function(str) {
var stack = arguments[1] || [];
if (str.charAt(0) == '') {
return stack.length === 0;
}
else if (str.charAt(0) == '{') {
stack.push(str);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cross-browser kerning-pairs & ligatures</title>
<style>
body { font-family: sans-serif; background: #f4f3f3; color: rgba(40, 30, 0, 1); width: 500px; margin: 80px auto; padding: 0px; }
a { color: rgba(15, 10, 0, 0.8); text-decoration: none; border-bottom: 1px solid; padding: 1px 1px 0px; -webkit-transition: background 1s ease; }
a:hover { background: rgba(0, 220, 220, 0.2); }
p, li { line-height: 1.5; padding: 0em 1em 0em 0em; margin: 0em 0em 0.5em; }
#!/usr/bin/env ruby
require 'net/http'
def validate(url)
uri = URI.parse(url)
response = Net::HTTP.get_response(uri)
case response
when Net::HTTPSuccess
return uri
<script>
/*
Transform a standard js object into a callable function with all the same properties as the original object.
*/
/* Variables */
var o = { test: 'data1', test2: 'data2' }
var func_body = function() { alert('hi'); }
/* Construction */
//
// Simple javascript truncate function
//
// Extend the string object to allow truncation
String.prototype.truncate = function(length) {
return this.length > length ? this.substring(0, length) + '&hellip;' : String(this);
}
// Usage
<?php
Class Helpers {
static function sort_by_length($a,$b){
if($a == $b) return 0;
return (strlen($a) > strlen($b) ? -1 : 1);
}
static function file_path_to_url($file_path) {
<?php
Class Page {
var $template;
var $partials;
#
# This faked data will be dynamically created (by searching through and parsing the /content folder) and stored within the Page class
#
var $data = array(