Skip to content

Instantly share code, notes, and snippets.

View derekdreery's full-sized avatar

Richard Dodd (dodj) derekdreery

View GitHub Profile
@derekdreery
derekdreery / web_error.rs
Created August 15, 2018 10:09
Experiments handling errors in wasm-bindgen.
#![feature(use_extern_macros, wasm_custom_section, wasm_import_module, proc_macro_mod)]
extern crate wasm_bindgen;
extern crate web_sys;
use wasm_bindgen::prelude::*;
use web_sys::{console, Node};
macro_rules! try_web {
($e:expr) => {
@derekdreery
derekdreery / unfinished_linked_list.rs
Created January 30, 2018 11:44
Unfinished linked list
use std::mem;
pub struct SimpleLinkedList<T> {
head: Link<T>
}
impl<T> SimpleLinkedList<T> {
pub fn new() -> Self {
SimpleLinkedList {
head: Link::Empty
import Html
import Html.Events as HtmlEvt
main =
Html.beginnerProgram
{ model = init
, view = view
, update = update
}
@derekdreery
derekdreery / removeSponsored.js
Created October 5, 2016 08:04
Remove facebook sponsored posts
// I find the inline sponsored posts on fb really annoying, and the ad-blockers don't seem to be able to keep
// up these days, so I wrote a script that takes a different approach. This js just needs to be run somewhere on the page
// Note that this javascript is written in modern ES2015, so you might need to change some of it in an older browser
function isSmall(el, minWidth, minHeight) {
const bbox = el.getBoundingClientRect();
return bbox.width < minWidth || bbox.height < minHeight;
}
" Convert all "import"s to "require"s
%s/^import \(\w\+\) from ['"]\([^'"]\+\)['"];$/const \1 = require("\2");/
@derekdreery
derekdreery / gist:f3c6dc8cc6578eb83f87
Last active August 29, 2015 14:09
Systemd containers

Systemd containers

Systemd container are an easy way to create containers for isolating programs onto private networks, which I do a lot when I'm doing web development.

It's really cool - both host and container run systemd and know how to communicate, and everything just works.

This guide derrives most stuff from the arch wiki, and tries to pull it into a single set of instructions.

@derekdreery
derekdreery / .vimrc
Created March 2, 2014 09:54
My .vimrc
set nocompatible
filetype off
" Set the runtime path to vundle and init
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
" Bundles
" -------
@derekdreery
derekdreery / ActiveRecord Tutorial.md
Last active August 29, 2015 13:56
ActiveRecord Tutorial

Groupoffice ActiveRecord Tutorial

License

This document has no copyright protection whatsoever and you are free to do as you please with it. I don't take any responsibility for anything you do with this information though.

Introduction

The groupoffice ActiveRecord.php is a custom implementation of the [active record pattern][1] commonly used for database access from web applications. The system can seem complex and daunting at first, but as you get to know it you will find the time-saving features very helpful.

I may extend this to be a tutorial of the whole of groupoffice eventually.

This tutorial assumes you have a basic understanding of the groupoffice class autoloader and router. I give a quick recap below:

@derekdreery
derekdreery / gist:8141373
Created December 27, 2013 01:53
dot product
fn dot<T: Add<T, T> + Mul<T, T> + Zero>(u: ~[T], v: ~[T]) -> T {
let mut acc = Zero::zero();
let mut it = u.iter().zip(v.iter());
loop {
match it.next() {
Some((u, v)) => { acc = acc + *u * *v }
_ => { break; }
}
}