Skip to content

Instantly share code, notes, and snippets.

View benaubin's full-sized avatar

Ben Aubin benaubin

View GitHub Profile
@benaubin
benaubin / README.MD
Last active December 12, 2017 20:30
Alphabetizing your Bibliography: Because it sucks and Scienteer doesn't do it for you.

Put this link in your browser's address bar on the Scienteer Bibliography page. It'll alphabetize everything for you. Fancy 😃

javascript:var%20alphabetizedBib=jQuery(".newQuestionText").map(function(){return%20$(this).text()}).sort();jQuery(".newQuestionText").each(function(i){$(this).text(alphabetizedBib[i])});

If it doesn't work, paste it in then make sure that the javascript: part is before the code. Chrome hates its life has some nice security features so sometimes it decides to be terrible remove that important part (it's what tells the browser that the code is actually code and not some place you want to go).

@benaubin
benaubin / PhoneNumberFormatter.swift
Created January 8, 2018 21:47
Using PhoneNumberKit to... format phone numbers
import Foundation
import Cocoa
import PhoneNumberKit
@objc
class PhoneNumberFormatter: Formatter {
static private let phoneNumberKit = PhoneNumberKit()
static private let partialPhoneNumberFormatter = PartialFormatter()
@benaubin
benaubin / README.md
Last active May 3, 2020 22:26
Turbolinks w/ Google ReCAPTCHA V3
module SecureBearerToken
TOKEN_BYTES = 33
def self.generate_token
token = SecureRandom.random_bytes(TOKEN_BYTES)
hash = hash_decoded_token token
[Base64.urlsafe_encode64(token), hash]
end
use core::ptr::{self, NonNull};
use std::sync::atomic::{self, AtomicBool, AtomicPtr};
struct Shared<T: Send> {
hung_up: AtomicBool,
slot: AtomicPtr<T>,
}
pub struct Writer<T: Send>(NonNull<Shared<T>>);
pub struct Reader<T: Send>(NonNull<Shared<T>>);
@benaubin
benaubin / waker.rs
Last active January 16, 2021 22:49
turn a mio::waker into a std::task::waker
use std::{
sync::Arc,
task::{RawWaker, RawWakerVTable, Waker},
}
/// turn a mio::waker into a std::task::Waker
fn make_waker(waker: Arc<mio::Waker>) -> Waker {
static WAKER_VTABLE: &'static RawWakerVTable =
RawWakerVTable::new(clone_waker, wake, wake_by_ref, drop);
unsafe fn clone_waker(ptr: *const mio::Waker) -> RawWaker {
use std::{borrow::Cow, sync::{Arc, Weak}};
use std::io::{Read, Write, IoSlice, IoSliceMut};
const FRAME_BUFFER_MAX_LEN: usize = 8 * 1024;
pub struct FrameChannel {
queue: crossbeam::queue::SegQueue<Vec<u8>>,
waker: mio::Waker
}