Skip to content

Instantly share code, notes, and snippets.

/**
* HTML5 Placeholder Deprecation JS.
* Automatically support the placeholder attribute in browsers that don't support it.
*
* To emulate webkit, placeHolderActive class should probably contain something like:
* .placeholderActive { color: darkGray; }
*
* Chris Dary - chrisd@arc90.com
* Released under the WTFPL License : http://sam.zoy.org/wtfpl/
**/
readability.article.smoothScrolling = {
reversePageScroll : false, // If they hold shift and hit space, scroll up
/**
* How long it takes to scroll the page, in ms.
**/
scrollSpeed: 500,
/**
* The scrollable element, which changes depending on browser. Initialized via initScrollable.
@umbrae
umbrae / dashCaseToLowerCamelCase.js
Created April 22, 2011 13:24
Convert from Dash Case (some-string-like-this) to lowerCamelCase in Javascript
function dashCaseToLowerCamelCase(dashCaseString) {
return dashCaseString.replace(/-\w/g, function ($0) { return $0.substr(-1).toUpperCase(); });
}
@umbrae
umbrae / cors-xmlhttprequest.js
Created May 4, 2011 17:14
A simple raw CORS XMLHttp Library. Fully untested, but the jist should be there. Has no support for failing cases currently.
/**
* A simple CORS XMLHttp Library. Fully untested, but the jist should be there. Has no support for failing cases currently
*
* Should work in FF4, Webkit, and IE8+
* @param method string - like GET or POST
* @param url string - the URL to attempt to fetch
* @param data Object - a dictionary of parameters to pass if we're POSTing
* @param callback Function - a callback to be returned on success.
**/
@umbrae
umbrae / embed-sample.html
Created June 3, 2011 20:07
Read Now + Read Later + Send to Kindle
<!--
rbdWrapper can take several data- attributes:
1. data-url : to specificy a specific URL to link to (useful for index pages)
2. data-text-color : the text color of "Read". 6 digit hex or "transparent"
3. data-bg-color : the bg color. 6 digit hex or "transparent"
4. data-show-send-to-kindle : 1 or 0, whether to show the "send to kindle" button or not.
5. data-show-read : 1 or 0, whether to show the read buttons or not.
A sample is like:
-->
@umbrae
umbrae / approx-queryset.py
Created July 6, 2011 20:32
Adding MySQL detection to approximate count queryset, taken from here: http://www.tablix.org/~avian/blog/archives/2011/07/django_admin_with_large_tables/
from django.db import connections
from django.db.models.query import QuerySet
class ApproxCountQuerySet(QuerySet):
"""Counting all rows is very expensive on large Innodb tables. This
is a replacement for QuerySet that returns an approximation if count()
is called with no additional constraints. In all other cases it should
behave exactly as QuerySet.
Only works with MySQL. Behaves normally for all other engines.
@umbrae
umbrae / gist:1626720
Created January 17, 2012 14:03
gotime
# Step 1. Put some commented-out entries in your /etc/hosts file for sites you
# want to block while you're working, with a comment/hashtag of gotime, like
# this:
#127.0.0.1 reddit.com #gotime
#127.0.0.1 www.facebook.com #gotime
# Step 2. Add these lines to your shell's rc file:
alias gotime="sudo perl -pi -e 's/#([^\n]+)#gotime/\$1#gotime/g' /etc/hosts"
@umbrae
umbrae / genders.sql
Created January 17, 2012 19:00
Roughly detect gender by first name in SQL
-- This table is useful for rough statistics based on gender
-- Don't consider it scientific in any way.
--
-- Example use:
-- select COALESCE(
-- (SELECT gender
-- FROM gender_types
-- WHERE name=users.first_name
-- LIMIT 1),
-- 'U') gender_type, count(*)
@umbrae
umbrae / gist:1683249
Created January 26, 2012 15:22
Speed comparison of finding if a digit exists in a string, in python.
>>> cmd = """
... for c in 'xdtwkeltjwlkejt7wthwk89lk':
... if c.isdigit():
... break;
... """
>>>
>>> timeit.Timer(cmd).timeit()
2.1454498767852783
>>>
>>>
@umbrae
umbrae / gist:3305292
Created August 9, 2012 15:45
TextMate 2 at GitHub

( Mirror of http://blog.macromates.com/2012/textmate-2-at-github/ )

Today I am happy to announce that you can find the [source for TextMate 2 on GitHub][].

I’ve always wanted to allow end-users to tinker with their environment, my ability to do this is what got me excited about programming in the first place, and it is why I created the bundles concept, but there are limits to how much a bundle can do, and with the still growing user base, I think the best move forward is to open source the program.