Skip to content

Instantly share code, notes, and snippets.

export default function selectRandom(list, count) {
if (count < 1) return []
const pickIndex = Math.floor(Math.random() * list.length)
const pick = list[pickIndex]
const remainder = list.filter((item, index) => index !== pickIndex)
const result = [pick].concat(selectRandom(remainder, count - 1))
return result
-- <- double dash is the SQL way to say "the rest of this line is a comment"
-- Join tables are how you do many-to-many relationships
-- in relational databases, and they're just complicated
-- enough that it puts some people off. But once you get
-- used to them, I don't think they're too bad.
-- ** Creating Our Tables **
CREATE TABLE articles (

Keybase proof

I hereby claim:

  • I am neall on github.
  • I am neall (https://keybase.io/neall) on keybase.
  • I have a public key ASBZxyLklDClwI8RThgQcJ6hTor9s2cTfJeL4G86PG7XOQo

To claim this, I am signing this object:

@neall
neall / promiseTimeout.coffee
Created April 29, 2014 15:09
I wanted to make a promise-wrapped setTimeout that had a way to abort. I am not 100% happy with just giving the promise an abort() method.
promiseTimeout = (delay) ->
extraMethods = {}
promise = new Promise (resolve, reject) ->
handle = setTimeout(resolve, delay)
extraMethods.abort = (reason = new Error('timeout aborted')) ->
if handle
clearTimeout(handle)
reject(reason)
handle = false
promise.abort = extraMethods.abort
@neall
neall / methToFunc.js
Last active August 29, 2015 13:59
Take a method that depends on "this" and wrap it in a function call you can pass around. Also includes optional currying.
Object.defineProperty(Object.prototype, 'methToFunc', {
value: function(methodName) {
var method = this[methodName];
if (typeof method === 'function') {
var curryArgs = [].slice.call(arguments, 1);
var that = this;
return function() {
return method.apply(that, curryArgs.concat(arguments));
};
} else {
@neall
neall / app.css
Last active January 4, 2016 07:39
#previous {
background: blue;
height: 10px;
}
#next {
background: green;
height: 10px;
}
#timeline-container {
position: relative;
$ bundle exec rake test
Loaded suite /Users/neal/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/rake_test_loader
Started
...........................................................................................................................................................................................................................................................................................................................................................EEF..........................................................................................................................................................................................................................................................
Finished in 11.928274 seconds.
1) Error:
test_call_import_on_VirtualBox_with_proper_base(ImportVMActionTest):
NoMethodError: undefined method `clear_line' for #<Vagrant::UI:0x00000100f43958>
/Users/neal/source/vagrant/lib/vagrant/action/vm/import.rb:20:in `call'
<!DOCTYPE html>
<html>
<head>
<title>test filtering</title>
</head>
<body>
<input name=filter>
<ul>
<li>Cat</li>
<li>Dog</li>
@neall
neall / compiled.css
Created July 5, 2011 20:25
My SCSS mixin to give me a radial gradient over a linear gradient
.selector {
background: #f8ab2f;
background: -webkit-gradient(radial, 40% 0, 0, 100% 100%, 100,
color-stop(0, rgba(251, 215, 57, 0.5)),
color-stop(1, rgba(246, 128, 38, 0.5))),
-webkit-gradient(linear, 0 0, 0 100%,
color-stop(0, #fbd739),
color-stop(1, #f68026));
background: -webkit-linear-gradient(top, rgba(251, 215, 57, 0.5), rgba(246, 128, 38, 0.5)),
-webkit-radial-gradient(40% 0, farthest-corner, #fbd739, #f68026);