Skip to content

Instantly share code, notes, and snippets.

@mathieuancelin
mathieuancelin / Lens.java
Last active March 7, 2023 02:23
Lenses with Java 8
package bar.foo.lenses;
import java.util.function.BiFunction;
import java.util.function.Function;
public class Lens<A, B> {
private final Function<A, B> getter;
private final BiFunction<A, B, A> setter;
@AnalogJ
AnalogJ / sails_ducktyping_for_background_tasks.js
Created July 21, 2014 21:27
Ducktyping Sailsjs for Background Tasks via Kue. See http://blog.thesparktree.com
var _ = require('lodash'),
Waterline = require('waterline'),
path = require('path'),
url = require('url'),
kue = require('kue'),
redis = require('../../node_modules/sails/node_modules/socket.io/node_modules/redis'),
q = require('q')
////////////////////////////////////////////////////////////////////
@chalkers
chalkers / HTMLToMarkdown.js
Created February 22, 2011 06:12
Pass in a jQuery representation of an element ($container) you get markdown out.
function htmlToMarkdown($container) {
var $clone = $container.clone();
$("*",$clone).removeAttr("name").removeAttr("title").removeAttr("id")
var html = $clone.html();
html = standardiseHTML(html);
html = html.replace(/<a [^h]*href=["']([^"']*)["'][^>]*>([^<]*)<\/a>/gi, " [$2]($1)");
html = html.replace(/<em[^>]*>([^<]*)<\/em>/gi,"*$1*");
html = html.replace(/<strong[^>]*>([^<]*)<\/strong>/gi,"**$1**");
html = html.replace(/<i[^>]*>([^<]*)<\/i>/gi,"*$1*");
html = html.replace(/<b[^>]*>([^<]*)<\/b>/gi,"**$1**");
@trydionel
trydionel / backbone.rails.js
Created November 28, 2010 16:47
Makes Backbone.js play nicely with default Rails setup
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.