Skip to content

Instantly share code, notes, and snippets.

@kkspeed
kkspeed / gist:1dfb964009b19ae00ac3
Created March 2, 2015 18:37
Creating archives -- simple wrapper on Hakyll tags
module Hakyll.Web.Archives
( Archives
, buildArchives
, archiveField
, archiveRules) where
import Control.Applicative
import Data.List (intercalate, sort)
import Data.Time
import System.Locale (defaultTimeLocale)
@kkspeed
kkspeed / gist:f13fe23813ec09b066bd
Created May 5, 2015 05:08
Simple Python Parser for Leetcode 65 - Valid Number
# So.. I wrote a parser for that... I know there are many easier ways,
# but this parser just feels more generic and with a little extension
# for result handling, it can actually be extended to a fully functional
# recursive descendant parser.
# The parser is based on Monadic Parsing common in functional languages
class Parser:
def parse(self, a):
pass
@kkspeed
kkspeed / menumanager.moon
Created November 24, 2015 04:53
Moonscript implemenation of More Weapon Stats's menumanager
-- More Weapon Stats Moonscript Trial
-- orignally modified from menumanager.lua from TdlQ and KarateF22's MoreWeaponStats
-- at http://paydaymods.com/mods/138/MWS
-- translated into moonscript by kkspeed
class MoreWeaponStats extends _G.MoreWeaponStats
@_path = ModPath
@_data_path = "#{SavePath}more_weapon_stats.txt"
@settings = {
show_dlc_info: true,
separate_extended_stats: false,
@kkspeed
kkspeed / menumanager.lua
Created November 24, 2015 04:54
More Weapon Stats menumanager.lua
-- More Weapon Stats menumanager.lua
-- by TdlQ and KarateF22
-- at http://paydaymods.com/mods/138/MWS
_G.MoreWeaponStats = _G.MoreWeaponStats or {}
MoreWeaponStats._path = ModPath
MoreWeaponStats._data_path = SavePath .. "more_weapon_stats.txt"
MoreWeaponStats.settings = {
show_dlc_info = true,
separate_extended_stats = false,
show_spread_and_recoil = true,
@kkspeed
kkspeed / blackjack.hs
Created January 11, 2016 03:27
Blackjack simple simulation
{-# 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 ()
@kkspeed
kkspeed / render.py
Created January 17, 2016 04:47
Adding TOC automatic display for Google IO-2012 slide template
#!/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: .....
#
@kkspeed
kkspeed / my_bind.hpp
Last active January 12, 2019 22:19
C++ Possible Alternate Bind Implementation
// 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.
@kkspeed
kkspeed / toy_frp.cpp
Last active February 11, 2019 06:58
A toy C++ FRP framework
// 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.
@kkspeed
kkspeed / naive.rs
Created January 18, 2019 04:55
A naive Rust Functional Reactive Programming Framework
use std::cell::RefCell;
use std::rc::Rc;
struct Core<T> {
observers: Vec<Box<Fn()>>,
value: Option<T>,
}
impl<T> Core<T>
where
@kkspeed
kkspeed / type_list_fun.cc
Created January 27, 2019 07:47
Func with C++ type list
// 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.