Skip to content

Instantly share code, notes, and snippets.

@SpaceManiac
SpaceManiac / what.cpp
Created September 17, 2017 07:57
CommandLineToArgvW differs from argc/argv
D:\projects\Sandbox>"cpp/"a.exe "cpp/"a.exe
---- argc and argv think:
0: cpp/a.exe
1: cpp/a.exe
---- GetCommandLineW is:
"cpp/"a.exe "cpp/"a.exe
---- CommandLineToArgvW thinks:
0: cpp/
1: a.exe
2: cpp/a.exe
@SpaceManiac
SpaceManiac / hello.html
Created May 19, 2017 17:28
Hello World in raw WebAssembly
<meta charset="utf-8">
<script type="text/javascript" src="hello.js"></script>
@SpaceManiac
SpaceManiac / kwargs.rs
Created April 29, 2017 04:16
rough kwargs macro sketch
use std::borrow::Cow;
#[macro_export]
macro_rules! kwargs {
// pass no arguments
() => { |_| {} };
// in-progress variants
(@struct [$($attr:meta)*] $name:ident [$($decls:tt)*] $field:ident: $typ:ty, $($rest:tt)*) => {
kwargs!(@struct [$($attr)*] $name [$($decls)* $field: ::std::option::Option<$typ>,] $($rest)*);
};
@SpaceManiac
SpaceManiac / shortcircuit.rs
Created September 17, 2016 23:59
Initial sketch of user-defined short-circuiting && and || operators in Rust.
trait And<Rhs=Self> {
type Output;
fn short(&self) -> Option<Self::Output>;
fn and(self, rhs: Rhs) -> Self::Output;
}
trait Or<Rhs=Self> {
type Output;
fn short(&self) -> Option<Self::Output>;
fn or(self, rhs: Rhs) -> Self::Output;
extern crate memmap;
#[cfg(target_pointer_width = "32")]
const MAGIC_VALUE: usize = 0xdedbeef0;
#[cfg(target_pointer_width = "32")]
const WORD_SIZE: usize = 4;
#[cfg(target_pointer_width = "64")]
const MAGIC_VALUE: usize = 0xd0e0a0d0b0e0e0f0;
#[cfg(target_pointer_width = "64")]
const WORD_SIZE: usize = 8;
#![allow(non_camel_case_types)]
use std::mem;
// The Situation
struct ffi_Object;
type ffi_Callback = unsafe extern fn(*mut ffi_Object) -> u32;
extern fn ffi_push_callback(_: *mut ffi_Object, _: ffi_Callback) {}
// Dummy wrapper
struct Object {

Keybase proof

I hereby claim:

  • I am SpaceManiac on github.
  • I am spacemaniac (https://keybase.io/spacemaniac) on keybase.
  • I have a public key whose fingerprint is DB3B 2679 BD6D F878 2216 F940 87EB 20C4 5D61 EFD5

To claim this, I am signing this object:

@SpaceManiac
SpaceManiac / docs.rs
Created August 22, 2015 22:31
Demonstration of #[doc(inline)] not working as expected
mod ffi {
mod inner {
/// A Docs
pub type A = i32;
}
/// A Use Docs
#[doc(inline)]
pub use self::inner::A;
}
package spongetest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.api.Game;
import org.spongepowered.api.util.event.Subscribe;
import org.spongepowered.api.event.state.PreInitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
@SpaceManiac
SpaceManiac / FurnaceUpgrade.java
Created October 20, 2014 06:07
Double-speed furnace implementation, comments note how to make normal-speed.
package com.platymuus.bukkit.endmachines.machines;
import com.platymuus.bukkit.endmachines.MachineDescription;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;