Skip to content

Instantly share code, notes, and snippets.

danlucraft / schema.js
Last active January 17, 2020 09:04
Make sure there is always some text after a link inline, so typing after a link is not impossible
View schema.js
inlines: {
link: {
// No link should be present but empty (default normalize should remove
// it if this returns false).
text: function(string) {
return string.length !== 0
// If the text node after a link inline is empty...
danlucraft / day2.js
Created November 14, 2016 17:04
3D from Scratch: Day 2 Source
View day2.js
var PIXEL_WIDTH = 160
var PIXEL_HEIGHT = 120
var WIN_WIDTH = window.innerWidth
var WIN_HEIGHT = window.innerHeight
var ratio_width = WIN_WIDTH / PIXEL_WIDTH
var ratio_height = WIN_HEIGHT / PIXEL_HEIGHT
var pixel_size = Math.floor(Math.min(ratio_width, ratio_height))
danlucraft /
Last active August 29, 2015 14:07
use std::os;
fn choose_k<'r, T>(arr: &[&'r T], k: uint) -> Vec<Vec<&'r T>> {
if k > arr.len() {
} else if k == 0 {
} else {
let mut result: Vec<Vec<&T>> = choose_k(arr.slice(1, arr.len()), k - 1).into_iter().map(|v| {
let mut x = vec![arr[0]];
View Error 82:47 error: type mismatch: the type `collections::vec::Vec<collections::vec::Vec<uint>>`
implements the trait `core::iter::FromIterator<collections::vec::Vec<uint>>`, but the trait
`core::iter::FromIterator<&collections::vec::Vec<uint>>` is required (expected &-ptr, found struct
collections::vec::Vec) let b: Vec<Vec<uint>> = a.iter().collect();
error: aborting due to previous error

Keybase proof

I hereby claim:

  • I am danlucraft on github.
  • I am danlucraft ( on keybase.
  • I have a public key whose fingerprint is 7395 C2F4 B97D 3FB8 2CD2 B439 D8D7 ECC8 B94E 2764

To claim this, I am signing this object:

danlucraft / disqus.js
Last active March 19, 2020 20:33
Disqus embed code for a single page javascript app, with optional SSO.
View disqus.js
// Enable or reset Disqus for this page as required, with optional SSO.
// There must be a div with id "disqus_thread" when called.
// config is required and should have the format:
// {
// shortname: "..",
// title: "..",
// identifier: "..",
// url: ".."
View sortingArrayController.js
App.DesignsRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set("model", App.Design.findAll());
App.DesignsController = Ember.ArrayController.extend({
sortProperties: ["name"],
sortAscending: true
danlucraft / vcr_json_aware_matching.rb
Created July 10, 2013 11:31
How to make VCR not fail to match the request body because the JSON hashes have been serialised in a different order
View vcr_json_aware_matching.rb
VCR.configure do |v|
v.register_request_matcher :json_aware_body do |r1, r2|
r1.body == r2.body || (
r1.headers["Content-Type"].inspect =~ /json/ and JSON.parse(r1.body) == JSON.parse(r2.body))
VCR.use_cassette('example', :match_requests_on => [:json_aware_body]) do
danlucraft / gist:5722203
Last active December 18, 2015 03:59
Jenkins checks out the code into /workspaces/geoip-service/src
View gist:5722203
cd workspaces/geoip-service
rm -rf tmp
rm -rf src/geoip-service
rm -f geoip-service
mkdir tmp
mv src/* tmp/
mkdir src/geoip-service
mv tmp/* src/geoip-service/
echo $PWD
export GOPATH=$PWD
danlucraft / gist:5712925
Created June 5, 2013 10:14
Calling return in a block can have slightly subtle consequences. Here are some tests with comments that show how it works.
View gist:5712925
require 'minitest/autorun'
# Show what return in a block does to return values and code after the block is run
class TestReturn < Minitest::Unit::TestCase
def setup
@post_code_run = false
# Method under test