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
#include <iostream> | |
#include <map> | |
#include <memory> | |
using Formula = std::map<std::string, int>; | |
class ParseContext { | |
public: | |
ParseContext(const std::string& string, int position): | |
string_(string), position_(position) {} |
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::str::from_utf8; | |
fn main() { | |
println!( | |
"{}", | |
read_proto_raw(&[0x12, 0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67]).unwrap() | |
); | |
println!( | |
"{}", | |
read_proto_raw(&[0x1a, 0x03, 0x08, 0x96, 0x01]).unwrap() |
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
;; Assumes D3 is provided as foreign lib. Add following to :compiler section of build. | |
;; :foreign-libs [{:file "lib/d3.v5.js" | |
;; :provides ["d3"] | |
;; :requires ["d3"]}] | |
;; Then (require [d3]) in the code namespace. | |
(def performance-data [{:group 0 | |
:name "Update()" | |
:start 200 | |
:end 240} | |
{:group 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
// Demonstrates C++ type list. | |
// Author: Bruce Li (github.com/kkspeed) | |
// Licensed under BSD. | |
// Requires C++ 11 except Filter. Filter requires C++14. | |
#include <string> | |
#include <type_traits> | |
// A typelist is a list of types. The list is similar to | |
// lists in functional languages like Lisp. |
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; | |
struct Core<T> { | |
observers: Vec<Box<Fn()>>, | |
value: Option<T>, | |
} | |
impl<T> Core<T> | |
where |
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
// A toy C++ FRP framework. | |
// Author: Bruce Li (github.com/kkspeed) | |
// Licensed under BSD. | |
// | |
// Note: | |
// 1. Compiles with C++ 17 | |
// 2. Signal values are copy-constructable. Non-copyconstructable values | |
// could be wrapped in shared_ptr. | |
// 3. Signal graph is statically connected and unsubscription is not | |
// an option. |
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
// Alternative implementation of bind without using placeholders. | |
// usage: | |
// Given void func(int a, int b, int c); | |
// auto f = my_bind(func, 3, 2); | |
// Then f(5) is the same as func(3, 2, 5); | |
// Also if first parameter is a weak pointer, this bind does the | |
// weak check automatically. | |
// For weak check to work successfully, the function needs to have void | |
// return type. |
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
#!/usr/bin/env python | |
# Original template: Google io 2012: | |
# https://code.google.com/p/io-2012-slides/ | |
# Now you can add section to your slide's metadata, which makes it | |
# easier to adapt to academic presentation | |
# e.g: | |
# --- | |
# section: foo bar | |
# title: ..... | |
# |
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
{-# Language GeneralizedNewtypeDeriving #-} | |
import Data.Maybe (fromJust) | |
import System.Random (randomIO) | |
import Control.Applicative | |
import Control.Monad.State.Strict | |
newtype GameAction s a = GameAction { getAction :: StateT s Maybe a } | |
deriving (Monad, Applicative, Functor, MonadState s, Alternative) | |
condition :: (s -> Bool) -> GameAction s () |
NewerOlder