Skip to content

Instantly share code, notes, and snippets.

@jonleighton
jonleighton / base64ArrayBuffer.js
Last active April 19, 2024 21:54
Encode an ArrayBuffer as a base64 string
// Converts an ArrayBuffer directly to base64, without any intermediate 'convert to string then
// use window.btoa' step. According to my tests, this appears to be a faster approach:
// http://jsperf.com/encoding-xhr-image-data/5
/*
MIT LICENSE
Copyright 2011 Jon Leighton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@jonleighton
jonleighton / gist:7122210
Created October 23, 2013 16:48
Report Rails deprecation warnings to Honeybadger (useful in production if there might be lines of code not covered by your tests - the horror!). Place this in your config/environments/production.rb
ActiveSupport::Notifications.subscribe('deprecation.rails') do |name, start, finish, id, payload|
Honeybadger.notify(
error_class: "DEPRECATION WARNING",
error_message: payload[:message],
backtrace: payload[:callstack]
)
end
# save path on cd (chpwd is a zsh hook)
function chpwd {
pwd > ~/.last_dir
}
# restore last saved path on launch
if [[ -f ~/.last_dir ]]; then
cd $(cat ~/.last_dir)
fi
#!/bin/bash
set -e
export AWS_REGION="eu-west-1"
export COMMIT_ID=$1
# Docker Hub account with read-only access to the repository
export DOCKER_HUB_USERNAME="[FILL ME IN]"
export DOCKER_HUB_PASSWORD="[FILL ME IN]"
$ ./mach check -v
Fresh unicode-segmentation v1.2.0
Fresh language-tags v0.2.2
Fresh khronos_api v2.0.0
Fresh bitflags v0.9.1
Fresh lazycell v0.4.0
Fresh pkg-config v0.3.9
Fresh fnv v1.0.5
Fresh sig v0.1.1
Fresh lzw v0.10.0
(gdb) p textinput
$6 = core::cell::RefMut<script::textinput::TextInput<script_traits::ScriptToConstellationChan>> {value: 0x7fffeca35e48, borrow: core::cell::BorrowRefMut {borrow: 0x7fffeca35e40}}
(gdb) p textinput.get_absolute_selection_range()
Could not find function named 'core::cell::RefMut<script::textinput::TextInput<script_traits::ScriptToConstellationChan>>::get_absolute_selection_range'
(gdb) info functions get_absolute_selection_range
All functions matching regular expression "get_absolute_selection_range":
File components/script/textinput.rs:
static fn script::textinput::TextInput<script_traits::ScriptToConstellationChan>::get_absolute_selection_range<script_traits::ScriptToConstellationChan>(script::textinput::TextInput<script_traits::ScriptToConstellationChan> *) -> core::ops::range::Range<usize>;
(gdb) p textinput.get_absolute_selection_range<script_traits::ScriptToConstellationChan>()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>initial selection test</title>
</head>
<body id="home">
<form>
<input type="text" value="test">
<textarea>test</textarea>
WARNING: [Bourbon] [Deprecation] `linear-gradient` is deprecated and will be removed in 5.0.0. We suggest using an automated prefixing tool, like Autoprefixer.
on line 10 of /home/turnip/.gem/ruby/2.4.0/gems/bourbon-4.3.2/app/assets/stylesheets/_bourbon-deprecate.scss, in `_bourbon-deprecate'
from line 17 of /home/turnip/.gem/ruby/2.4.0/gems/bourbon-4.3.2/app/assets/stylesheets/_bourbon-deprecate.scss, in `_bourbon-deprecate-for-prefixing'
from line 7 of /home/turnip/.gem/ruby/2.4.0/gems/bourbon-4.3.2/app/assets/stylesheets/css3/_linear-gradient.scss, in `linear-gradient'
from line 134 of /home/turnip/Code/wikihouse.cc/app/assets/stylesheets/_landing.scss
from line 34 of /home/turnip/Code/wikihouse.cc/app/assets/stylesheets/application.scss
WARNING: [Bourbon] [Deprecation] `_linear-positions-parser` is deprecated and will be removed in 5.0.0.
on line 3 of /home/turnip/.gem/ruby/2.4.0/gems/bourbon-4.3.2/app/assets/stylesheets/helpers/_linear-positions-pars

Keybase proof

I hereby claim:

  • I am jonleighton on github.
  • I am jonleighton (https://keybase.io/jonleighton) on keybase.
  • I have a public key whose fingerprint is F2BB 4F53 1DDB FCF6 6D9D AF23 3652 F01B 67BA C232

To claim this, I am signing this object:

@jonleighton
jonleighton / code.ex
Created February 9, 2017 18:41
Which is better?
# Option 1
list |> List.wrap |> Enum.map(&(&1["value"]))
# Option 2
Enum.map(List.wrap(list), &(&1["value"]))