This file contains hidden or 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
| // ©2012 Viktor Klang | |
| // 5,804 bytes compressed. | |
| package java.klang | |
| import java.util.concurrent.ConcurrentLinkedQueue; | |
| import java.util.concurrent.Executor; | |
| import java.util.concurrent.RejectedExecutionException; | |
| import java.util.concurrent.atomic.AtomicBoolean; | |
| public class Actor { |
This file contains hidden or 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
| //! Container for resources, that can be any type. This is inspired by Shred and AnyMap. | |
| //! AnyMap didn't fill my usecase as there is no way to borrow mutably 2 values for different | |
| //! keys. (`get_mut(&mut self)`). | |
| //! | |
| //! This container is using interior mutability with `RefCell` to allow this usecase. | |
| //! Downcasting trait does not work with pure rust so I am using a crate called `downcast_rs` to | |
| //! do it. | |
| //! | |
| //! | |
| //! How to use. |
This file contains hidden or 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
| Alright, so the basic problem is you have some system with a behavior | |
| described by a differential equation, but you either know that no | |
| classical (smooth) solution exists, or you think it might but aren't sure. | |
| For example, say you need 2nd derivatives somewhere but you know the | |
| problem must have C^2 discontinuities elsewhere because you have | |
| constraints that enforce them! Another example is you have | |
| poles/singularities but don't know where. (If you know in advance that | |
| you're gonna have poles in a specific location, you can exclude that | |
| location from consideration by removing it from your domain; but if you |
This file contains hidden or 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
| // Rule N0: | |
| // "Any number of characters that had original bidirectional character type NSM prior to | |
| // the application of W1 that immediately follow a paired bracket which changed to L or R | |
| // under N0 should change to match the type of their preceding bracket." | |
| // | |
| // We don't store the character types as they were before W1 persistently. However, we do | |
| // store the initial character types before any of the rules get applied (since they're | |
| // required for processing of rules L1/L2). Now the only relevant way that a NSM type | |
| // can get modified prior to rule W1 is due to directional overrides. But this can't | |
| // affect us: if there's directional overrides active around the bracket pair, e.g. |
This file contains hidden or 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
| # Here's a probably-not-new data structure I discovered after implementing weight-balanced trees with | |
| # amortized subtree rebuilds (e.g. http://jeffe.cs.illinois.edu/teaching/algorithms/notes/10-scapegoat-splay.pdf) | |
| # and realizing it was silly to turn a subtree into a sorted array with an in-order traversal only as an | |
| # aid in constructing a balanced subtree in linear time. Why not replace the subtree by the sorted array and | |
| # use binary search when hitting that leaf array? Then you'd defer any splitting of the array until inserts and | |
| # deletes hit that leaf array. Only in hindsight did I realize this is similar to the rope data structure for strings. | |
| # Unlike ropes, it's a key-value search tree for arbitrary ordered keys. | |
| # | |
| # The main attraction of this data structure is its simplicity (on par with a standard weight-balanced tree) and that it | |
| # coalesces subtrees into contiguous arrays, which reduces memory overhead and boosts the performance of in-order traversals |
This file contains hidden or 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
| #include <stdint.h> | |
| #define BITKNIT_BRANCHLESS_RENORM | |
| // RAD-esque types | |
| typedef size_t UINTa; | |
| typedef uint8_t U8; | |
| typedef uint16_t U16; | |
| typedef uint32_t U32; |
This file contains hidden or 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
| class Map | |
| def initialize width, height | |
| @values = Array.new(width){ Array.new(height){ nil } } | |
| end | |
| def [](x, y) | |
| @values[x][y] | |
| end | |
| def []=(x, y, value) |
This file contains hidden or 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
| // ---- triangle rasterizer | |
| #define SUBPIXEL_SHIFT 8 | |
| #define SUBPIXEL_SCALE (1 << SUBPIXEL_SHIFT) | |
| static RADINLINE S64 det2x2(S32 a, S32 b, S32 c, S32 d) | |
| { | |
| S64 r = (S64) a*d - (S64) b*c; | |
| return r >> SUBPIXEL_SHIFT; | |
| } |
This file contains hidden or 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
| ;; | |
| ;; NS CHEATSHEET | |
| ;; | |
| ;; * :require makes functions available with a namespace prefix | |
| ;; and optionally can refer functions to the current ns. | |
| ;; | |
| ;; * :import refers Java classes to the current namespace. | |
| ;; | |
| ;; * :refer-clojure affects availability of built-in (clojure.core) | |
| ;; functions. |
This file contains hidden or 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
| // float->sRGB8 conversions - two variants. | |
| // by Fabian "ryg" Giesen | |
| // | |
| // I hereby place this code in the public domain. | |
| // | |
| // Both variants come with absolute error bounds and a reversibility and monotonicity | |
| // guarantee (see test driver code below). They should pass D3D10 conformance testing | |
| // (not that you can verify this, but still). They are verified against a clean reference | |
| // implementation provided below, and the test driver checks all floats exhaustively. | |
| // |
OlderNewer