Skip to content

Instantly share code, notes, and snippets.

View nvzqz's full-sized avatar
🐣
Hatching ideas

Nikolai Vazquez nvzqz

🐣
Hatching ideas
View GitHub Profile
@nvzqz
nvzqz / choose.rs
Last active December 1, 2017 16:45
`Choose` trait for rand crate
#![feature(specialization)]
extern crate rand;
use rand::Rng;
trait Choose {
type Item;
fn choose<R: Rng>(self, rng: &mut R) -> Option<Self::Item>;
}
@nvzqz
nvzqz / assert_eq_size.rs
Last active December 5, 2017 06:36
Assert equal type size in Rust
use std::mem::transmute;
macro_rules! assert_eq_size {
($x:ty, $($xs:ty),+ $(,)*) => {
$(let _ = transmute::<$x, $xs>;)+
};
($label:ident; $($rest:tt)+) => {
#[allow(dead_code, non_snake_case)]
fn $label() {
assert_eq_size!($($rest)+);
@nvzqz
nvzqz / const_assert.rs
Created November 2, 2017 13:48
Constant assertions in Rust
macro_rules! const_assert {
($($condition:expr),+ $(,)*) => {
let _ = [(); 0 - !($($condition)&&+) as usize];
};
($label:ident; $($rest:tt)+) => {
#[allow(non_snake_case, dead_code)]
fn $label() {
const_assert!($($rest)+);
}
};

Where you able to produce a binary directly from the Rust build tools that you could submit to the app/play store?


Not quite, but I tried to get as close to that as was reasonably possible. Alas, things ended up a little convoluted.

For iOS, I have a nearly empty Xcode project with a build script that copies my cargo produced executable into the .app that Xcode generates (before Xcode signs it). The build script also uses lipo to merge the executables for each architecture I’m targeting (e.g. armv7 and aarch64 for non-simulator devices) into a single, universal binary.

On top of that, there are various iOS-y things that need to happen before my application’s main method is called. SDL2 provides the Objective-C code that does all of that. In a C or C++ game, SDL2 renames main to SDL_main, and then [inserts its own mai

#!/usr/bin/env swift
import Foundation
let arguments = Process.arguments
guard arguments.count > 1 else {
fputs("Error: Location argument missing.\n", stderr)
exit(EXIT_FAILURE)
}
@nvzqz
nvzqz / pacinstall.sh
Last active December 26, 2015 22:25
Bash script to install favorite packages
#!/usr/bin/env bash
################################
# Homebrew
# http://brew.sh
################################
brewtaps=(
homebrew/dupes
homebrew/versions
@nvzqz
nvzqz / .zshrc
Last active May 25, 2023 12:02
.zshrc for OS X
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# ZSH_THEME="gianu"
# ZSH_THEME="minimal"
# ZSH_THEME="dst"
@nvzqz
nvzqz / Dark Kolors.dvtcolortheme
Created May 30, 2015 21:33
Custom Xcode theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 1 1 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Menlo-Bold - 11.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>1 1 1 1</string>
@nvzqz
nvzqz / Preferences.sublime-settings
Last active August 29, 2015 14:15
Sublime Text Preferences
{
"caret_style": "solid",
"centurion_color_blue": true,
"color_scheme": "Packages/User/peacock.tmTheme",
"detect_indentation": true,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": false,
"find_selected_text": true,
"font_face": "Source Code Pro",
"font_size": 12.0,