Skip to content

Instantly share code, notes, and snippets.

View djg's full-sized avatar
💭
I may be slow to respond.

Dan Glastonbury djg

💭
I may be slow to respond.
View GitHub Profile
@djg
djg / gist:9e6bd46486d4f44cc3662ef8cc44a8ce
Created February 14, 2019 05:44
Belgium/Dutch/Euro Sound of Adelaide '91-'93
In no particular order:
Space Master - I Need You (Master Mix) https://www.youtube.com/watch?v=Qg0VjVXVoXk
Afrika Bambaataa - Feeling Irie https://www.youtube.com/watch?v=z2VdfIA7N7o
House Pimps - Zulu Nation https://www.youtube.com/watch?v=zrXnzJ0Mn0E
The Badman Presents N.D.X. - Come With Me https://www.youtube.com/watch?v=EUDW_LWbtQM
Tainted Two - The Megablast https://www.youtube.com/watch?v=oHd8Sk-7WIU
Digital Domain - I Need Relief https://www.youtube.com/watch?v=zrXnzJ0Mn0E
Problem house - Party people https://www.youtube.com/watch?v=MNQitcvJKlw
DJ Hype - Shot in The Dark (Q Bass Remix) https://www.youtube.com/watch?v=0O40o6RvoH8
Mig-29 - Mig-29 (Love Mix) https://www.youtube.com/watch?v=4oqqMbmIhkQ
@djg
djg / fhdl.rs
Created January 18, 2019 02:34
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::{
fold::Fold,
parse::{Parse, ParseStream, Result},
parse_quote,
punctuated::Punctuated,
Expr, ExprLit, FieldValue, Ident, ItemFn, LitStr, Local, Member, Pat, Stmt, Token,
};
@djg
djg / image.rs
Created December 16, 2018 23:36
WebRender ImageKey and ImageTemplate
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct ImageKey {
pub common: PrimKeyCommonData,
pub key: ApiImageKey,
pub stretch_size: SizeKey,
pub tile_spacing: SizeKey,
pub color: ColorU,
pub sub_rect: Option<DeviceIntRect>,
@djg
djg / gross.rs
Created September 14, 2018 02:49
SIMD in Rust is kinda gross.
// Type your code here, or load an example.
#[cfg(target_arch = "x86")]
use std::arch::x86::__m128;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::__m128;
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2"))]
pub struct Ray {
pub pt: __m128,
pub dir: __m128,
@djg
djg / halpstahp.rs
Created September 14, 2018 02:30
functional programming cry for help
pub fn hit_zip(aabb: &Aabb, r: &Ray, t_min: f32, t_max: f32) -> bool {
r.direction
.iter()
.zip(
r.point
.iter()
.zip(aabb.min.iter().zip(aabb.max.iter())),
).all(|(d, (p, (min, max)))| {
let inv_d = 1. / d;
let t0 = (min - p) * inv_d;
@djg
djg / after.cpp
Created March 15, 2018 06:59
verilated-rs generated binds to verilator simulation class.
#include <Vtop.h>
extern "C" {
// CONSTRUCTORS
Vtop*
top_new() {
return new Vtop();
}
void
@djg
djg / context.rs
Created March 2, 2018 00:26
Pulse Audio Callbacks
type ServerInfoCB = FnMut(&ContextRef, Option<&ServerInfoRef>) + Send + Sync + 'static;
pub fn get_server_info<CB>(&self, cb: CB) -> Result<Operation>
where
CB: FnMut(&ContextRef, Option<&SourceInfo>) + Send + Sync + 'static,
{
let userdata = Box::into_raw(Box::new(cb)) as *mut c_void;
let cb: ffi::pa_server_info_cb_t = Some(c_get_server_info_cb);
op_or_err!(
self,
// Samples are delta-encoded
pub fn unpack_sample<T: Default + ops::AddAssign + Clone>(input: &[u8])
-> Result<Vec<T>, &'static str> {
if input.len() % mem::size_of::<T>() != 0 {
return Err("packed sample data is not aligned");
}
let packed_sample: &[T] = unsafe {
slice::from_raw_parts(input.as_ptr() as *const T,
input.len() / mem::size_of::<T>())
@djg
djg / sample.rs
Created January 19, 2018 06:50
Rust future/result and_then style control flow.
open_server_stream().ok()
.and_then(|stream| UnixStream::from_stream(stream, &handle).ok())
.and_then(|stream| bind_and_send_client(stream, &handle, &tx_rpc))
.ok_or_else(|| io::Error::new(
io::ErrorKind::Other,
"Failed to open stream and create rpc."
))
@djg
djg / two_8.8_one_reg.txt
Created August 14, 2017 01:19
Adding two numbers in one register
Square by Pulse does this trick of adding two 8.8 fixed numbers in
"one 40-bit register" in the inner loop of it's pin-mapping routine. I
wonder if this is a known bit-twiddling trick documented some where?
(It feels like Lamport's 1976 paper where u is a 23 bit number)
Say we have u and v in 8.8 fixed point format and we want to increment
those by some signed deltas du and dv also in 8.8 fixed point.
I'll only consider a negative du because that seems to be an
interesting case in the code. Eg. let u = v = 64 = 64.00 = 0x4000 and