Skip to content

Instantly share code, notes, and snippets.

View gmbeard's full-sized avatar

Greg Beard gmbeard

  • Rochdale, UK
  • 10:53 (UTC +01:00)
View GitHub Profile
@gmbeard
gmbeard / gist:23c77114cd4c1bc3103d
Created January 5, 2015 19:43
Chaining std::bind to perform arbitrary searches of custom types using std::find_if
#include <iostream>
#include <functional>
#include <vector>
class Item
{
private:
std::string m_ItemId;
int m_Price;
int m_Count;
@gmbeard
gmbeard / test.js
Created January 22, 2015 10:57
Testing prototype inheritance in Chrome v8
"use strict";
var c = new A_Child();
c.methodA();
c.methodB();
@gmbeard
gmbeard / zero_padded.cpp
Created September 17, 2015 14:36
Parse zero-padded number
#include <iostream>
#include <string>
#include <stdexcept>
int main(int, char *[])
{
using std::string;
using std::cin;
using std::cout;
using std::endl;
@gmbeard
gmbeard / service_manager.cpp
Created November 1, 2015 20:31
A simple "Service Manager" implementation
#include <iostream>
#include <unordered_map>
#include <memory>
#ifdef _DEBUG
#include <cassert>
#endif
namespace gmb
{
struct service_id { };
@gmbeard
gmbeard / rotate_and_read_search.rs
Last active December 7, 2016 22:00
Non-allocating search for a word in a stream by rotate-and-read
use std::io::Read;
fn fill(buf: &mut [u8]) {
for (i, n) in buf.iter_mut().enumerate() {
*n = i as u8;
}
}
fn rotate<T: Copy + Default>(buf: &mut [T], at: usize) -> usize {
use std::ops::Deref;
pub trait Crypto {
type Output;
type Error;
fn encrypt(&mut self) -> Result<Self::Output, Self::Error>;
}
impl<'a, T: Crypto> Crypto for &'a mut T {
.text
.def _ZN50_$LT$asm_bug..Rot13$u20$as$u20$asm_bug..Crypto$GT$7encrypt17hbaabafb2f8efe03fE;
.scl 2;
.type 32;
.endef
.globl __xmm@bfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbf
.section .rdata,"dr",discard,__xmm@bfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbf
.p2align 4
__xmm@bfbfbfbfbfbfbfbfbfbfbfbfbfbfbfbf:
.zero 16,191
.text
.def _ZN50_$LT$asm_bug..Rot13$u20$as$u20$asm_bug..Crypto$GT$7encrypt17hbaabafb2f8efe03fE;
.scl 2;
.type 32;
.endef
.section .text,"xr",one_only,_ZN50_$LT$asm_bug..Rot13$u20$as$u20$asm_bug..Crypto$GT$7encrypt17hbaabafb2f8efe03fE
.globl _ZN50_$LT$asm_bug..Rot13$u20$as$u20$asm_bug..Crypto$GT$7encrypt17hbaabafb2f8efe03fE
.p2align 4, 0x90
_ZN50_$LT$asm_bug..Rot13$u20$as$u20$asm_bug..Crypto$GT$7encrypt17hbaabafb2f8efe03fE:
movq 16(%rcx), %r11
@gmbeard
gmbeard / future_internals.rs
Created December 6, 2017 17:52
Rough implementation of Rust's Future / Stream traits, to demonstrate their combinators and ownership semantics
use std::mem;
enum Chain<T, F, U> {
First(T, F),
Second(U),
Done,
}
impl<T, F, U> Future for Chain<T, F, U>
where T: Future,

Keybase proof

I hereby claim:

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

To claim this, I am signing this object: