Skip to content

Instantly share code, notes, and snippets.

View benaubin's full-sized avatar

Ben Aubin benaubin

View GitHub Profile
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
}
@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 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>>);
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
@benaubin
benaubin / README.md
Last active May 3, 2020 22:26
Turbolinks w/ Google ReCAPTCHA V3
@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 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 / setup.js
Created November 17, 2017 20:10
My hacky way to install ghost apps.
var APPS_TO_INSTALL = ["section-from-content"];
// install or remove
var action = "install";
// don't change the following
var _ = require('lodash');
var Promise = require('bluebird');
@benaubin
benaubin / __Skyline.md
Last active October 23, 2017 05:15
Some sample files from Skyline - my refreshingly beautiful modern Ghost Theme.

Skyline is a refreshlingly-beautiful Ghost theme.

Defined by the images that cover the top of your home page, Skyline leaves a great impression on your vistors that starts the instance they open your site. Your posts are layed out as fabulous cards that tile down the page.

I paid an amazing amount of detail as I designed Skyline. Every option in Ghost's markdown processor supports looks amazing in Skyline. Beautiful fonts add to the artistry of the theme. Full-bleed images and videos take up the full width of the screen. Authors are recognized with their picture and bio after each of their posts. Skyline has great built in support for [Facebook][fb-comments], [Disqus][disqus] and [Carnival][carnival] and can be easily extended to support others. Even subscriptions and error pages are custom designed to match the atmosphere of your site. We love it so much, it's the theme we use for this very site!

To recap, Skyline has:

  • Beautiful cover images
  • Amazing index layouts
@benaubin
benaubin / theme-license.md
Last active October 3, 2017 22:46
A license for themes you purchase from me.

We grand you, the purchaser of the theme, a non-exclusive wordwide license to use of the item under the terms that follow:

You're allowed to use this item in as many sites as you'd like owned by yourself.

You may not sell or redistribute this theme or any derivatives created using it, although you may transfer this license.

If you transfer the license, you must immediatly cease using the theme on any sites and destroy any copies of the theme you may have made.

You may make modifications to the theme, but you'll still have to follow the terms of this license.