Skip to content

Instantly share code, notes, and snippets.

@avibryant
avibryant / gist:3200554
Created July 29, 2012 17:47
The Regex Game
The Regex Game
Avi Bryant
This is a game for two programmers, although it's easy to imagine variations for more.
It can be played over email, twitter, or IM, but it's easy to imagine a custom web app for it, and I encourage someone to build one.
Each player starts by thinking of a regular expression. The players should decide beforehand on dialect and length restrictions (eg, has to be JavaScript-compatible and under 20 characters).
They don't reveal the Regex, but if playing over email etc, should send each other a difficult to brute force hash (eg bcrypt) of the Regex for later verification.
They do reveal two strings: one which the Regex will match, and one which it will not.
-- Solution to http://beust.com/weblog/2011/10/30/a-new-coding-challenge/
import Data.List(isInfixOf)
partitions n 1 = [[n]]
partitions n k | n > 0 = [m:ms | m <- [1..n `div` 2], ms <- partitions (n-m) (k-1)]
partitions n k | otherwise = []
weighings [] = [0]
weighings (w:ws) = [m + n | m <- weighings ws, n <- [-w, 0, w]]
@avibryant
avibryant / loess.js
Created August 17, 2011 15:45
Loess smoothing
//adapted from the LoessInterpolator in org.apache.commons.math
function loess_pairs(pairs, bandwidth)
{
var xval = pairs.map(function(pair){return pair[0]});
var yval = pairs.map(function(pair){return pair[1]});
console.log(xval);
console.log(yval);
var res = loess(xval, yval, bandwidth);
console.log(res);
return xval.map(function(x,i){return [x, res[i]]});
@maccman
maccman / hr.less
Created July 11, 2011 18:47
HR CSS3 Tapering
/* See http://cl.ly/8KmQ for an example */
hr {
margin: 15px 0;
position: relative;
border: 1px solid transparent;
.box-shadow(0, 1px, 2px, rgba(0,0,0,0.3));
&:before, &:after {
content: "";
@jed
jed / LICENSE.txt
Created May 10, 2011 16:04 — forked from 140bytes/LICENSE.txt
write contextual templates
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
@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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>saveActiveFile</string>
<key>command</key>
<string># This uses the cli for the less compiler
# it should work with either the node module or the ruby gem (which is really old)
@danott
danott / modernizr-tests.js
Created March 4, 2011 16:55
Custom Modernizr tests that are useful.
/* modernizr-test.js
* Daniel Ott
* 3 March 2011
* Custom Tests using Modernizr's addTest API
*/
/* iOS
* There may be times when we need a quick way to reference whether iOS is in play or not.
* While a primative means, will be helpful for that.
*/
@omni5cience
omni5cience / MeetupBug.md
Created February 21, 2011 19:43
A description of a bug I'm having with meetup boards.

So I've noticed a problem with meetup boards: Whenever I want to post to a board I can type in a message, but can't submit it.

Below the Message field there's a <ul> with a single <li> that says You will only be required to do this once. which is particularly unhelpful.

If I try to submit the form I get an error that says You entered a bad response. Please try again. I also noticed that there is a <div> below that with some reCaptcha widget that starts out with display: none; set on it. If I remove that there is a broken reCaptcha that I'm guessing is supposed to be what I'm only required to do once.

Right now the only way I can get around this is to turn off javascript and use the iFrame backup. (For reference, this only seems to work occasionally.)

@HenrikJoreteg
HenrikJoreteg / JS Util solution using underscore.js
Created October 22, 2010 21:20
Rather than creating some other util global, just extend underscore.js with any additional methods you want.
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&amp;')
.replace(/>/g,'&gt;')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');