Skip to content

Instantly share code, notes, and snippets.

View dirvine's full-sized avatar

David Irvine dirvine

View GitHub Profile
@dirvine
dirvine / urls.txt
Created September 11, 2020 10:32 — forked from jgamblin/urls.txt
Top 1000 Domains
google.com
youtube.com
facebook.com
baidu.com
yahoo.com
amazon.com
wikipedia.org
google.co.in
twitter.com
qq.com
@dirvine
dirvine / i3 config
Last active November 28, 2018 15:25
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see https://i3wm.org/docs/userguide.html for a complete reference!

Keybase proof

I hereby claim:

  • I am dirvine on github.
  • I am dirvine (https://keybase.io/dirvine) on keybase.
  • I have a public key ASA2eTly6DqSDQl54W0_CvfbASdSiA_xvXcQsl_jnPrQFwo

To claim this, I am signing this object:

@dirvine
dirvine / rust-python-cffi.md
Created September 1, 2016 23:25 — forked from seanjensengrey/rust-python-cffi.md
Calling Rust from Python/PyPy using CFFI (C Foreign Function Interface)

This is a small demo of how to create a library in Rust and call it from Python (both CPython and PyPy) using the CFFI instead of ctypes.

Based on http://harkablog.com/calling-rust-from-c-and-python.html (dead) which used ctypes

CFFI is nice because:

  • Reads C declarations (parses headers)
  • Works in both CPython and PyPy (included with PyPy)
  • Lower call overhead than ctypes
use std::net::{IpAddr, SocketAddr, UdpSocket};
fn main() {
let local_addr = SocketAddr::new(IpAddr::new_v4(0, 0, 0, 0), 3671 );
let mut socket = match UdpSocket::bind(&local_addr) {
Ok(s) => s,
Err(e) => panic!("couldn't bind socket: {}", e),
};
match socket.join_multicast(&IpAddr::new_v4(224, 0, 23, 12)) {
Err(why) => println!("! {}", why),
@dirvine
dirvine / rust_examples.md
Last active August 29, 2015 14:17
playpen urls
@dirvine
dirvine / lib.rs
Last active August 29, 2015 14:16
dynamic dispatch - rust
/* Copyright 2014 MaidSafe.net limited
This MaidSafe Software is licensed to you under (1) the MaidSafe.net Commercial License,
version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which
licence you accepted on initial access to the Software (the "Licences").
By contributing code to the MaidSafe Software, or to this project generally, you agree to be
bound by the terms of the MaidSafe Contributor Agreement, version 1.0, found in the root
directory of this project at LICENSE, COPYING and CONTRIBUTOR respectively and also
available at: http://www.maidsafe.net/licenses
Unless required by applicable law or agreed to in writing, the MaidSafe Software distributed
under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
@dirvine
dirvine / crtp.cc
Last active August 29, 2015 14:14
example inherit/crtp forwarding ctr for derived from base
#include <iostream>
#include <string>
using namespace std;
template <typename Child>
struct Routing {
Routing() = delete;
explicit Routing(std::string s) : t(s) {}
void Get() { static_cast<Child*>(this)->FacadeGet(); }
@dirvine
dirvine / async_result.h
Created December 11, 2014 14:44
aync_result example
#include "maidsafe/common/test.h"
#include <iostream>
#include "asio/io_service.hpp"
#include "asio.hpp"
// Note: the handler signatures here must contain
// boost::system::error_code as first argument (not std::error_code)
// for asio to understand it is to indicate errors.
template <typename CompletionToken>
@dirvine
dirvine / lrucache.h
Last active August 29, 2015 14:10
LRUcache / filter scratchpad
/*
A last recently used cache that has a capacity and time to live setting. Passing a void ValueType
allows this object to be used as a firewall / filter type device that can hold and check
for keys already seen. Users can set the capacity, time_to_live or both allowing a cache that will
not hold data too long or stay full if it not being accessed frequently. This should
allow the cache to not hold stale information at the cost of a check every time we add that looks
at the timestamp of the last entry in the list and compares this to the maps timestamp.
Research links
http://en.wikipedia.org/wiki/Cache_algorithms