Skip to content

Instantly share code, notes, and snippets.

@seivan
seivan / main.rs
Last active November 20, 2018 18:44
gfx-rs. 3.2
#[macro_use]
extern crate gfx;
extern crate gfx_window_sdl;
extern crate sdl2;
use gfx::Device;
pub type ColorFormat = gfx::format::Srgba8;
pub type DepthFormat = gfx::format::DepthStencil;
@seivan
seivan / mod.rs
Created October 11, 2018 23:34
Events on UIViewController
//! iOS support
//!
//! # Building app
//! To build ios app you will need rustc built for this targets:
//!
//! - armv7-apple-ios
//! - armv7s-apple-ios
//! - i386-apple-ios
//! - aarch64-apple-ios
//! - x86_64-apple-ios
@seivan
seivan / mod.rs
Created October 11, 2018 22:14
Sans UIApplication & UIApplicationDelegate
//! iOS support
//!
//! # Building app
//! To build ios app you will need rustc built for this targets:
//!
//! - armv7-apple-ios
//! - armv7s-apple-ios
//! - i386-apple-ios
//! - aarch64-apple-ios
//! - x86_64-apple-ios
template size_t handle_map::erase(Id_T handle)
{
if (!isValid(handle)) { return 0; }
m_fragmented = 1;
Id_T innerId = m_sparseIds[handle.index];
uint32_t innerIndex = innerId.index;
// push this slot to the back of the freelist
innerId.free = 1;
@seivan
seivan / rants.md
Last active September 26, 2018 09:51
Rant

The borrow checker is solid. The communication with it, is a UX fail. As indicative by the tutorials that write pseudo code to try to teach you how it works using named scopes.
By now, I get how it works but it's hard to predict in a when you're not exactly sure how to solve certain technical issues, or even how the final design of an API of several modules will look like. Forcing you go back and forth between lifetimes, implementations and what not. two steps forward, eleven back. It's a failure that the borrow checker does not adapt to what I am trying to achieve instead of telling me it's impossible - when I am very much aware, it's possible.

Ideas: Figure out what variations of smart pointers and mutexes will work in combination to do what I am trying to achieve and make it happen - this essentially gets rid of the borrow checker as your code becomes reference counted instead of compile error. Performance and execution becomes unpredictable as you have no idea what's going to happen once you execu

@seivan
seivan / CustomFileHandler.swift
Created September 24, 2018 08:56
Long running Swift process (for running under BeamVM through ports)
////
//// CustomFileHandler.swift
//// StatefulProcess
////
//// Created by Seivan Heidari on 18/07/03.
////
//
import Foundation
#if os(Linux)
import Glibc
@seivan
seivan / world.cpp
Created September 22, 2018 19:56
C++ ECS prototype
#include <map>
#include <memory>
#include <set>
#include <typeindex>
#include <vector>
// ────────────────────────────────────────────────────────────────────────────────
struct Position {};
struct Weapon {};
@seivan
seivan / world.cpp
Created September 22, 2018 19:55
N variadic tuple
#include <iostream>
#include <string>
#include <type_traits>
class Frombler {
public:
virtual void fromble() = 0;
};
class Foo : public Frombler {
@seivan
seivan / UndefinedBehaviour.swift
Created August 31, 2018 07:49
This shouldn't work, but it works. Thus undefined behaviour.
func update(_ arg: inout String) {
arg = "UPDATED \(arg)"
}
public class SystemWork {
let mainQueue = DispatchQueue.init(label: "mainQueue", qos: .userInitiated, attributes: [], autoreleaseFrequency: .inherit, target: nil)
let workerQueue = DispatchQueue.init(label: "workerQueue", qos: .userInitiated, attributes: [.concurrent], autoreleaseFrequency: .inherit, target: nil)
let systemQueue = DispatchQueue.init(label: "systemQueue", qos: .userInitiated, attributes: [.concurrent], autoreleaseFrequency: .inherit, target: nil)
@seivan
seivan / BitSetPerformanceTests.swift
Created July 27, 2018 17:59
`BitSet / BitVector / BitArray` using `UnsafeMutablePointer` instead of `Array<T>`
import XCTest
import Foundation
final class Ref {
var value : UnsafeMutablePointer<Int>
init(_ v : UnsafeMutablePointer<Int>) {value = v}
deinit {
self.value.deallocate()