Skip to content

Instantly share code, notes, and snippets.

@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 / composition.rb
Created April 9, 2015 17:09
Function composition in Ruby
class Lambda < Proc
def initialize(&block)
@block = block
end
def >> (g)
Lambda.new {|*args| g[*self[*args]]}
end

Keybase proof

I hereby claim:

  • I am davidjbeveridge on github.
  • I am davidjbeveridge (https://keybase.io/davidjbeveridge) on keybase.
  • I have a public key whose fingerprint is 9D0B 4BC5 447D 567B 781F 444A 10FE 4DB3 1D93 A65E

To claim this, I am signing this object:

@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('');
}
@davidjbeveridge
davidjbeveridge / Y-Fibinator.js
Last active August 29, 2015 14:14
anonymous [memoized] fibonacci range, using y-combinator in JavaScript
(function(Y, memoize){
return (function(range, map, fib) {
return function(a, b) {
return map(fib, range(a, b));
};
})(
Y(function(range, a, b, inc) {
inc = inc || 1;
if(a === b) return [a];
return [a].concat(range(range, a+1, b));

Keybase proof

I hereby claim:

  • I am davidjbeveridge on github.
  • I am davidjbeveridge (https://keybase.io/davidjbeveridge) on keybase.
  • I have a public key whose fingerprint is 9D0B 4BC5 447D 567B 781F 444A 10FE 4DB3 1D93 A65E

To claim this, I am signing this object:

@davidjbeveridge
davidjbeveridge / partial_right.js
Last active August 29, 2015 14:05
Right-associative parital application
// Some assertion functions we can play with
function assert(condition, message) {
if(!condition) {
throw new Error(message);
}
}
function assert_equal(obj1, obj2) {
assert(obj1 === obj2, 'Expected '+obj1+' to equal '+obj2+'.');
}
@davidjbeveridge
davidjbeveridge / partial.js
Created August 19, 2014 16:23
Partial Application
// Some assertion functions we can play with
function assert(condition, message) {
if(!condition) {
throw new Error(message);
}
}
function assert_equal(obj1, obj2) {
assert(obj1 === obj2, 'Expected '+obj1+' to equal '+obj2+'.');
}
@davidjbeveridge
davidjbeveridge / create_instance.js
Created August 12, 2014 18:18
Homework #1: create instances without the `new` operator
/** Write a function that will emulate the behavior of the `new` operator. I
* should be able to pass it a constructor function and some arguments, and get
* back an instance of it. Here's a test case; just fill in the
* `createInstance` function.
*
* You can just run the code to see if it works; if it doesn't work, assert will
* throw errors.
*
* To run it, just use `node create_instance.js`
*/

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