This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sort_cards(cards, mask_suits=False): | |
if isinstance(cards, str): | |
cards = cards.split(' ') | |
suits, ranks = 'cdhs', '23456789TJQKA' | |
ranks_rev = dict((ranks[i], i) for i in range(13)) | |
cards = [(s, tuple(sorted(ranks_rev[c[0]] for c in cards | |
if c[1] is s))) for s in suits] | |
cards = [c for c in cards if c[1] != ()] | |
cards.sort(key=lambda c: (-len(c[1]), c[1])) | |
if mask_suits: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def parse_to_df(files): | |
rank_values = dict(zip(tuple('23456789TJQKA'), range(13))) | |
records = [] | |
for hand in h_iterators.HandsIterator( | |
hh_iterator=h_iterators.HandHistoryIterator(files)): | |
for i, card in enumerate(hand['hero']['cards'].split(' ')): | |
records.append({'card_rank': (rank_values[card[0]], card[0]), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from collections import namedtuple | |
Vertex = namedtuple('Vertex', 'id, edges') | |
Edge = namedtuple('Edge', 'edge_from, edge_to, label, weight') | |
def load_graph(filename): | |
with open(filename) as f: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (unfoldr, minimumBy) | |
import Data.Char (isSpace) | |
import Data.Function (on) | |
import Data.Maybe (mapMaybe, fromMaybe) | |
import System.Environment (getArgs) | |
import qualified Data.ByteString.Char8 as L | |
import qualified Data.IntMap as IM | |
type GraphData = (IM.IntMap (IM.IntMap [(Int, Int)]), Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.traits; | |
import std.exception; | |
bool maybeError(T)(T v) { | |
static if (is(T == function) || is (T : void *)) | |
return v is null; | |
else static if (isIntegral!T) | |
static if (isSigned!T) | |
return v < 0; | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.traits; | |
import std.string; | |
import std.typetuple; | |
template ID(alias T) { | |
alias ID = T; | |
} | |
private bool _propertyNameMatches(alias parent, string suffix, alias name)() { | |
static if (!__traits(compiles, __traits(getMember, parent, name))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.typecons; | |
import std.stdio; | |
import std.string; | |
import std.conv; | |
struct Box(T) if (is(T == class)) | |
{ | |
@disable this(); | |
this(Args...)(Args args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[allow(unstable)] | |
extern crate libc; | |
#[allow(unstable)] | |
mod test { | |
use libc::c_int; | |
use std::sync::{StaticMutex, MUTEX_INIT}; | |
static LOCK: StaticMutex = MUTEX_INIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::RefCell; | |
use std::rc::Rc; | |
use std::collections::HashMap; | |
use std::collections::hash_map::Entry; | |
#[derive(Debug)] | |
struct Handle { | |
id: Rc<RefCell<i32>>, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-------------------------------------------------------------------------------- | |
Ir | |
-------------------------------------------------------------------------------- | |
158,791,478,749 PROGRAM TOTALS | |
-------------------------------------------------------------------------------- | |
Ir file:function | |
-------------------------------------------------------------------------------- | |
10,231,292,690 collections::hash::map::robin_hood | |
9,273,922,532 collections::hash::table::RawBucket<_>::offset |
OlderNewer