Skip to content

Instantly share code, notes, and snippets.

@timyates
timyates / lenstest.groovy
Last active January 3, 2016 05:29
Functional Lenses and Groovy
import groovy.transform.*
// Immutable test object
def tim = new Person( 'tim', new Address( 'Woo', 123 ) )
// Lens for setting address for a person
Lens personAddress = new Lens( { p -> p.address }, { p, a -> new Person( p.name, a ) } )
// And one for setting zipcode for an address
Lens addressZipcode = new Lens( { a -> a.zip }, { a, z -> new Address( a.street, z ) } )
@willurd
willurd / web-servers.md
Last active July 10, 2025 04:43
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@ssylvan
ssylvan / rh_hash_table.hpp
Last active July 2, 2025 14:23
Quick'n'dirty Robin Hood hash table implementation. Note, I have implemented this algorithm before, with tons of tests etc. But *this* code was written specifically for the blog post at http://sebastiansylvan.com/post/robin-hood-hashing-should-be-your-default-hash-table-implementation/, it has not been extensively tested so there may be bugs (an…
#define USE_ROBIN_HOOD_HASH 1
#define USE_SEPARATE_HASH_ARRAY 1
template<class Key, class Value>
class hash_table
{
static const int INITIAL_SIZE = 256;
static const int LOAD_FACTOR_PERCENT = 90;
struct elem
@ForbesLindesay
ForbesLindesay / Real World Specification.md
Last active January 4, 2022 22:41
Functional Programming from the perspective of a JavaScript Programmer.

Real World Specification

(aka "Algebraic JavaScript Specification")

This project specifies the behavior of a number of methods that may optionally be added to any object. The motivation behind this is to encourage greater code reuse. You can create functions that just rely on objects having implementations of the methods below, and in doing so you can make them work with a wide variety of different, but related data structures.

Definitions

For the purposes of this, spec, an "entity" is an object that has an [[equivalent]] operation (see bellow) and may implement some or all of the other methods.

@jareware
jareware / SCSS.md
Last active June 16, 2025 21:34
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@guipn
guipn / then.js
Created November 4, 2012 05:44
Function.prototype.then
function square(x) {
return x*x;
}
function add3(x) {
return x + 3;
}
function sub10(x) {
return x - 10;
@johan
johan / README.md
Last active April 18, 2025 15:35
A micro-library (4k minified) for DRY:ing up the boring boilerplate of user scripts.

The fun part of user scripting is deciding what happens. The boring part is scavenging the DOM for bits of templated data, or elements you want to mod.

Have on.js do it for you!

@johan
johan / on.js
Created October 14, 2012 00:47
Stand-alone version of dotjs / user script utility function "on", for limiting script invocation to pages with particular content, and scraping that content for you. Origin: https://raw.github.com/johan/user.js/master/default.js
/* coffee-script example usage - at https://github.com/johan/dotjs/commits/johan
on path_re: ['^/([^/]+)/([^/]+)(/?.*)', 'user', 'repo', 'rest']
query: true
dom:
keyboard: 'css .keyboard-shortcuts'
branches: 'css+ .js-filter-branches h4 a'
dates: 'css* .commit-group-heading'
tracker: 'css? #gauges-tracker[defer]'
johan_ci: 'xpath* //li[contains(@class,"commit")][.//a[.="johan"]]'
@puffnfresh
puffnfresh / do.sjs
Created October 4, 2012 04:40
do-notation using sweet.js
macro $do {
case { $y:expr } => {
$y
}
case { $x:ident <- $y:expr $rest ... } => {
λ['>=']($y, function($x) {
return $do { $rest ... }
});
}
}
@equivalent
equivalent / README.md
Last active December 16, 2021 16:34
String "false" to_bool ... or how to convert Rails/SimpleForm radio buttons to boolean

This gist was writen in 2012 and it was solving specific problem in Rails & SimpleForm. Some fellow developers were pointing out this may be out dated concept. That's why I advise everyone to read comment section bellow to have a full grasp of alternative solutions

other sources that may be helpful to understand why this may not be best idea: