Skip to content

Instantly share code, notes, and snippets.

@zeux
zeux / diaenum.fs
Created April 22, 2012 22:34
F# generic enumeration helper
// helpers to iterate IDiaEnum* objects
let inline toSeq (o: ^T) =
let e = { new IEnumerable with member this.GetEnumerator () = (^T: (member GetEnumerator: unit -> _) (o)) }
if true then
Seq.cast e
else
// Dummy expression to constrain return type to that of o.Item
seq [| (^T: (member Item: _ -> _) (o, Unchecked.defaultof<_>)) |]
@zeux
zeux / _.vim
Created August 4, 2012 06:44
.vimrc
" english menu/messages (should be the first line of _vimrc!)
language C
" activate pathogen
call pathogen#infect()
" enable syntax highlighting
syntax on
" color scheme
namespace Collections
open System
open System.Collections
[<AbstractClass>]
type LazyList<'T>() =
static let notimpl () = raise $ NotImplementedException()
abstract member Item: int -> 'T
Vector3 getLightContributionZ1(float x, float y)
{
float wedgeVolumeX = x / 2;
float wedgeVolumeY = y / 2;
float cornerVolume = x * y / 6;
float contribX = wedgeVolumeX - cornerVolume;
float contribY = wedgeVolumeY - cornerVolume;
return Vector3(contribX, contribY, 1 - contribX - contribY);
11:12:45.60360 (6.4333265) 6.43333 0.0 ms 6164:LightGrid: Grid moved, reuploading luminance
11:12:46.61360 (6.6403439) 6.64034 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 206849 usec
11:12:46.61360 (6.6413441) 6.64134 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 967 usec
11:12:46.61360 (6.6423442) 6.64234 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 1025 usec
11:12:46.61360 (6.6433443) 6.64334 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 964 usec
11:12:46.61360 (6.6443444) 6.64434 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 1080 usec
11:12:46.61360 (6.6453445) 6.64534 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 961 usec
11:12:46.61360 (6.6463446) 6.64634 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 982 usec
11:12:46.61360 (6.6473447) 6.64734 0.0 ms 6164:RBX::LightGrid::lightingUploadChunk took 981 usec
11:12:46.61360 (6.6483448) 6.64834 0.0 ms 6164:RBX::LightGrid
@zeux
zeux / p4checkout.py
Last active December 13, 2015 19:48
import sublime, sublime_plugin
import os, stat
import subprocess
import _thread
class P4Checkout(sublime_plugin.EventListener):
def on_modified(self, view):
def checkout(file):
output = subprocess.check_output(["p4", "edit", file], shell=True)
print(output.decode())

Parsing XML at the speed of light

Preface

@zeux
zeux / tablescanopt.c
Last active December 18, 2015 04:39
Наш ответ С++ оптимизаторам (http://habrahabr.ru/post/182428/)
// 1. Идея в том, чтобы заменить сравнения сложением с overflow в специально оставленный carry bit;
// поскольку каждое значение имеет свой carry bit, сложения можно делать "параллельно" uint64 операциями
// 2. Очевидно, решение "почти" кроссплатформенно и почти C (наверное, скомпилируется как C99?).
// Из существенного тут используется знание о порядке bitfields -- мне не хотелось переписывать весь
// код на битовые операции с uint64 -- и нарушается strict aliasing. Очевидно, исправляется просто.
// 3. А вот и тайминги (cl64 /Ox /TP):
// Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
// Generated rows: 100000000
// C-search took 0.778000 seconds.
// C++-optimized search took 0.307000 seconds.
@zeux
zeux / tablescanopt.cpp
Created June 7, 2013 05:50
Я просто оставлю это здесь...
#include <stdio.h> /* printf, scanf, NULL */
#include <stdlib.h> /* calloc, exit, free */
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
#include <memory> // std::unique_ptr<>
#include <array> // std::array<>
#include <type_traits> // std::enable_if<>
#include <iostream> // std::cout
#include <map> // std::map<>
#include <stdio.h>
template <typename R, typename F> R callf(void* buffer, F func)
{
return func();
}
template <typename R, typename F, typename ArgHead, typename ...ArgTail> R callf(void* buffer, F func)
{
ArgHead* head = static_cast<ArgHead*>(buffer);