Skip to content

Instantly share code, notes, and snippets.

@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 {}
@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: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 / 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 / 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 / VRCompositorCommand.rs
Created November 23, 2016 20:31
VRCompositorCommand for blogpost
pub enum VRCompositorCommand {
Create(VRCompositorId),
SyncPoses(VRCompositorId, f64, f64, IpcSender<Result<Vec<u8>,()>>),
SubmitFrame(VRCompositorId, [f32; 4], [f32; 4]),
Release(VRCompositorId)
}
@MortimerGoro
MortimerGoro / TypedArrays.rs
Created November 23, 2016 20:34
TypedArrays example for blogpost
/// Creates a typed JS array from a Rust slice
pub fn slice_to_array_buffer_view<T>(cx: *mut JSContext, data: &[T]) -> *mut JSObject
where T: ArrayBufferViewContents
{
unsafe {
let js_object = T::new(cx, data.len() as u32);
assert!(!js_object.is_null());
update_array_buffer_view(js_object, data);
js_object
}
@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 / VRDisplay.rs
Last active November 23, 2016 21:51
VRDisplay DOM struct example
#[dom_struct]
pub struct VRDisplay {
eventtarget: EventTarget,
#[ignore_heap_size_of = "Defined in rust-webvr"]
display: DOMRefCell<WebVRDisplayData>,
depth_near: Cell<f64>,
depth_far: Cell<f64>,
presenting: Cell<bool>,
left_eye_params: MutHeap<JS<VREyeParameters>>,
right_eye_params: MutHeap<JS<VREyeParameters>>,
@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>);
}