Skip to content

Instantly share code, notes, and snippets.

@DarinM223
DarinM223 / homebrew.txt
Created April 13, 2017 13:00
Adding homebrew openssl so that cmake can find it
This should fix the problem:
ln -s /usr/local/Cellar/openssl/1.0.2k/include/openssl/ /usr/local/include/openssl
@DarinM223
DarinM223 / regex.rs
Last active April 28, 2017 21:20
Regex
#[macro_use]
extern crate log;
extern crate env_logger;
use std::borrow::Cow;
use std::collections::HashSet;
use std::mem;
use std::ptr;
use std::result;
use std::string::FromUtf8Error;
@DarinM223
DarinM223 / profile_results.txt
Created May 1, 2017 22:06
Mold2d Profile results
1190ms of 1320ms total (90.15%)
Showing top 10 nodes out of 61 (cum >= 890ms)
flat flat% sum% cum cum%
650ms 49.24% 49.24% 850ms 64.39% [nouveau_dri.so]
130ms 9.85% 59.09% 1320ms 100% [libc-2.23.so]
80ms 6.06% 65.15% 1320ms 100% [game]
70ms 5.30% 70.45% 120ms 9.09% [libdrm_nouveau.so.2.0.0]
60ms 4.55% 75.00% 930ms 70.45% [libSDL2-2.0.so.0.4.0]
50ms 3.79% 78.79% 50ms 3.79% [libpthread-2.23.so]
50ms 3.79% 82.58% 200ms 15.15% update
@DarinM223
DarinM223 / rustfmt.toml
Created May 3, 2017 04:24
A saner rustfmt configuration file
array_layout = "Visual"
chain_indent = "Block"
array_width = 80
chain_one_line_max = 80
comment_width = 80
condense_wildcard_suffices = false
closure_block_indent_threshold = 2
control_brace_style = "AlwaysSameLine"
disable_all_formatting = false
error_on_line_overflow = true
@DarinM223
DarinM223 / magic.md
Last active January 29, 2024 06:19
C++ magical template examples:

Generic constraints

In Rust it is easy to constrain a generic type to only include types extending from some interface. For example:

pub trait DoSomething {
    fn do_something(&self);
}
@DarinM223
DarinM223 / precedence.rs
Last active May 25, 2017 09:39
Simple parser for arithmetic expressions using precedence climbing
#[macro_use]
extern crate lazy_static;
extern crate regex;
use regex::{CaptureMatches, Regex};
use std::collections::HashMap;
use std::num::ParseIntError;
use std::result;
use std::str::FromStr;
@DarinM223
DarinM223 / build.gradle
Last active May 22, 2017 02:56
Kotlin examples
group 'd_m'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.2-2'
repositories {
mavenCentral()
}
dependencies {
@DarinM223
DarinM223 / err_code.cpp
Last active May 29, 2017 12:17
C++ exception-less C-style error handling
#include <iostream>
#include <string>
#include <system_error>
struct PersonError {
enum {
TOO_OLD = 1,
NAME_TOO_SHORT = 2,
};
};
@DarinM223
DarinM223 / server.ex
Last active June 5, 2017 05:14
OTP stash worker state management example
defmodule Sequence.Server do
use GenServer
# Public API
def start_link(agent_id) do
GenServer.start_link(__MODULE__, agent_id, name: __MODULE__)
end
def next_number do
@DarinM223
DarinM223 / graph.ex
Last active June 5, 2017 04:41
Elixir algorithms
defmodule Algorithms.Graph.Node do
alias Algorithms.Graph.Node
defstruct data: nil, edges: []
def bfs(id, storage, visited, f) do
if Map.has_key?(visited, id) do
[]
else
visited = Map.put(visited, id, true)