Skip to content

Instantly share code, notes, and snippets.

@davidjbeveridge
davidjbeveridge / addToBuffer.js
Last active March 1, 2024 07:51
Buffer bookmarklet
(function() {
function bufferUrl(url, title) {
baseUrl = "http://bufferapp.com/add?";
return [baseUrl,
"url=",
encodeURIComponent(url),
"&text=",
encodeURIComponent(title)
].join('');
}

Add to Buffer (in iframe)

Use this handy javascript snippet to add an "Add to Buffer" bookmark. Then you can add anything to your Buffer, anytime, all without leaving the page.

How it works

First, copy the following into your clipboard (it's the attached Javascript, but formatted as a bookmarklet):

javascript:(function()%7Bfunction%20c(a%2Cb)%7BbaseUrl%3D%22%2F%2Fbufferapp.com%2Fadd%3F%22%3Breturn%20baseUrl%2B%22url%3D%22%2Bd(a)%2B%22%26text%3D%22%2Bd(b)%7Dvar%20d%3DencodeURIComponent%3Bc(window.location.href%2Cwindow.document.title)%3Bvar%20a%3Ddocument.createElement(%22iframe%22)%3Ba.setAttribute(%22style%22%2C%22width%3A%20900px%3B%20height%3A%20500px%3B%20position%3A%20fixed%3B%20top%3A%2050%25%3B%20left%3A%2050%25%3B%20margin-left%3A%20-450px%3B%20margin-top%3A%20-250px%3B%20background%3A%20%23fff%3B%20border%3A%20solid%201px%20%23000%3B%20z-index%3A%201000%3B%22)%3Ba.setAttribute(%22frameborder%22%2C%220%22)%3Burl%3Dc(document.location.href%2Cdocument.title)%3Ba.src%3Durl%3Bdocument.body.a
@davidjbeveridge
davidjbeveridge / ascii2dvorak.js
Created January 19, 2017 17:02
ASCII-Dvorak Conversion
var asciiChars = `qwertyuiop[]\asdfghjkl;'zxcvbnm,./QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?`;
var dvorakChars = `',.pyfgcrl/=\aoeuidhtns-;qjkxbmwvy"<>PYFGCRL?+|AOEUIDHTNS_:QJKXBMWVY`;
function ascii2dvorak(str) {
return str.replace(/./g, function (ch) {
var index = asciiChars.indexOf(ch);
if(index === -1) return ch;
return dvorakChars.charAt(index);
})
}
@davidjbeveridge
davidjbeveridge / ajaxSpy.js
Created January 23, 2014 19:34
utility for spying on jQuery.ajax request by url, type, data.
var ajaxSpy = (function($){
var oldAjax = $.ajax;
var requests = [];
var watchers = [];
function newAjax(opts){
// execute real $.ajax and save the promise
var promise = oldAjax.apply(this, arguments);
requests.push({
opts: opts,
1075446353799203608005222047954026648916985018736581275753957497919839201623062887108721238807090848775021233760505186276438761497628718313149293175492755964685299434067108769528175430469423430061224064134888298650648205437920120403949631508956152559756188631959778290070643186622664875761846921766320383330860641231669497209040038077155027094109100466684104868860172692233512833407904643636044479840607123525858089016669511195551342610686077687896153683341897904992123861154943231617441207762969246167447753839618170201505400277058903800509767455975921283551524825711820638926971423748415355075057220848003095975436512897675614177005302585376395860084950971646483190331493537275840263066908452501651327026817692918216857663786238273533278053604714843805103802595548879565827410480101450006914802010323621032427750751014021958919466809270231408989645550289257201025616453072054558525073602481994601974714740025917272965189244586918777770442352148397581651051391096829792054910040180994636018505347027812313732698892543429416
@davidjbeveridge
davidjbeveridge / curry.coffee
Created July 17, 2013 06:31
More stable currying w/ variable args
curry = (fn, args...) ->
old_args = args.slice()
currier = (x...) ->
if arguments.length is 0
val = fn(args...)
args = old_args
val
else
args = [args..., x...]
currier
class Card extends Spine.Model
@configure 'Card', 'id', "name", "parent_id", "lft", "rgt",
"high_person_week", "created_at", "updated_at", "project_id",
"low_person_week", "type", "data"
@extend Spine.Model.Ajax
@url: '/cards'
url: -> "/projects/#{@project_id}/cards/#{@id}"
@davidjbeveridge
davidjbeveridge / httpd.conf
Last active December 12, 2015 08:28
Apache config for CORS on Chrome
Header append Access-Control-Allow-Origin: *
Header append Access-Control-Allow-Credentials: true
Header append Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, DELETE
Header append Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control
@davidjbeveridge
davidjbeveridge / fizzbuzz_constant.rb
Created November 27, 2012 22:25
FizzBuzz in constant time
def fizzbuzz(n)
[
'FizzBuzz',
1,
2,
'Fizz',
4,
'Buzz',
'Fizz',
7,
@davidjbeveridge
davidjbeveridge / fibonacci_benchmark.coffee
Created October 26, 2012 21:47
javascript function memoization benchmark
fib1 = (index) ->
if index < 2
1
else
fib1(index - 1) + fib1(index - 2)
fib2 = (index) ->
hash = {}
fib2 = (index) ->
hash[index] or= if index < 2