Skip to content

Instantly share code, notes, and snippets.

@MortimerGoro
MortimerGoro / VRCompositor.rs
Last active November 29, 2016 19:08
VRCompositor traits for blogpost
// Trait object that handles WebVR commands.
// Receives the texture_id associated to the WebGLContext.
pub trait VRCompositorHandler: Send {
fn handle(&mut self, command: VRCompositorCommand, texture_id: Option<u32>);
}
@MortimerGoro
MortimerGoro / WebVRThread.rs
Created November 23, 2016 20:29
WebVRThread example for blogpost
while let Ok(msg) = self.receiver.recv() {
match msg {
WebVRMsg::RegisterContext(context) => {
self.handle_register_context(context);
self.schedule_poll_events();
},
WebVRMsg::UnregisterContext(context) => {
self.handle_unregister_context(context);
},
WebVRMsg::PollEvents(sender) => {
@MortimerGoro
MortimerGoro / main.rs
Last active November 29, 2016 21:58
VRServiceManager example
let mut vr = VRServiceManager::new();
// Register default VRService implementations.
// Default VRServices are specified using cargo features.
vr.register_defaults();
// Fallback to Mock Device if no real headset is found.
vr.register_mock();
// Intialize all registered VR Services
vr.initialize_services();
// Discover VR devices
let devices = vr.get_devices();
@MortimerGoro
MortimerGoro / VRService.rs
Created November 23, 2016 20:27
VRService traits for blogpost
pub trait VRService: Send {
fn initialize(&mut self) -> Result<(), String>;
fn fetch_devices(&mut self) -> Result<Vec<VRDevicePtr>, String>;
fn is_available(&self) -> bool;
fn poll_events(&self) -> Vec<VRDisplayEvent>;
}
@MortimerGoro
MortimerGoro / VRDevice.rs
Last active November 23, 2016 21:12
VRDevice traits for blogpost
pub trait VRDevice: Send + Sync {
// Returns unique device identifier.
fn device_id(&self) -> u64;
// Returns the current display data.
fn display_data(&self) -> VRDisplayData;
// Returns the inmediate VRFrameData of the HMD.
// Should be used when not presenting to the device.
@MortimerGoro
MortimerGoro / gist:ab1dd3963a021e3c2c2f
Created August 14, 2014 18:31
MGSwipeTableCell right buttons
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * reuseIdentifier = @"cell";
MGSwipeTableCell * cell = [self.tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"Description";
@MortimerGoro
MortimerGoro / AmbiguityOption1
Created June 25, 2014 20:30
Bison Ambiguity
Option 1,
statements -> <Rule 11, tokens 1 .. 8>
statement -> <Rule 2, tokens 1 .. 1>
expression -> <Rule 343, tokens 1 .. 1>
prefix_expression -> <Rule 347, tokens 1 .. 1>
prefix_operator_opt -> <Rule 348, empty>
postfix_expression -> <Rule 424, tokens 1 .. 1>
primary_expression -> <Rule 362, tokens 1 .. 1>
"ID" <tokens 1 .. 1>
generic_argument_clause_opt -> <Rule 363, empty>
@MortimerGoro
MortimerGoro / gist:73103944326698e57f34
Created June 4, 2014 10:55
Receipt validation using OpenSSL and asn1c.
/* The PKCS #7 container (the receipt) and the output of the verification. */
BIO *b_p7;
PKCS7 *p7;
/* The Apple root certificate, as raw data and in its OpenSSL representation. */
BIO *b_x509;
X509 *Apple;
/* The root certificate for chain-of-trust verification. */
X509_STORE *store = X509_STORE_new();
@MortimerGoro
MortimerGoro / gist:10901996
Created April 16, 2014 16:21
Deep interface hierarchies bung on Android 2.3: LinearAlloc exceeded
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
interface A1 {}
interface A2 {}
interface A3 {}
interface A4 {}