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
import weakref | |
class memoized_property(property): | |
def __init__(self, *args, **kwargs): | |
super(memoized_property, self).__init__(*args, **kwargs) | |
self.data = weakref.WeakKeyDictionary() | |
def __get__(self, instance, owner=None): |
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
import math | |
def parse(expression, variables=None, context=vars(math)): | |
variables = ','.join(variables) if variables is not None else '' | |
context = dict(context) if context is not None else {} | |
return eval('lambda {}: {}'.format(variables, expression), None, context) |
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
import qualified Data.Char as Char | |
data Things t = Things {thing :: t, quantity :: Int} | |
instance (Show t) => Show (Things t) | |
where | |
show t = if quantity t == 1 then get t else get t ++ "s" | |
where | |
get = filter (not . (`elem` "\"")) . show . thing | |
makeSentence :: (Show t) => [Things t -> String] -> t -> Int -> String |
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
import Data.Ratio | |
import Text.Read | |
import System.Environment | |
wallis_succession :: [Rational] | |
wallis_succession = merge odds evens | |
where | |
odds = [n % (n - 1) | n <- [2, 4..]] | |
evens = [n % (n + 1) | n <- [2, 4..]] | |
merge (x:xs) (y:ys) = x : y : merge xs ys |
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 <stdio.h> | |
#define COUNT(...) (sizeof((int[]){ __VA_ARGS__ })/sizeof(int)) | |
#define __eval(x0, x1, x2, x3, ...) _Generic((x0), \ | |
void*: _Generic((x1), int: _evali, double: _evald), \ | |
int: _evali, \ | |
double: _evald \ | |
)( \ | |
COUNT(__VA_ARGS__) - _Generic((x0), void *: 1, default: 0), \ |
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
# Customize prompt | |
export PROMPT_COMMAND="BRANCH=\ | |
\"\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\"" | |
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]"\ | |
"\h:\[\033[33;1m\]\w\[\033[m\]\[\033[0;36m\]\${BRANCH}\[\033[0m\]\$ " | |
# Customize command line | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxBxDxCxegedabagacad | |
alias ls="ls -GFh" |
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
syntax on | |
filetype indent off | |
set backspace=indent,eol,start | |
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab | |
let g:netrw_banner = 0 | |
let g:netrw_liststyle = 3 | |
let g:netrw_browse_split = 4 | |
let g:netrw_altv = 1 |
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 <string_view> | |
#include <string> | |
#include <tuple> | |
class Joint { | |
std::string _j; | |
auto& _concat(std::string& s, std::string_view sv) { return s += sv; } | |
template<typename... Args> |
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 <functional> | |
#include <tuple> | |
#include <type_traits> | |
template<typename T, typename U, typename V> | |
class ReduceOperator { | |
T _init; | |
U _apply; | |
V _chain; |
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 <memory_resource> | |
template<typename T> | |
class contiguous_memory_resource : public std::pmr::memory_resource { | |
std::pmr::memory_resource* _upstream; | |
std::size_t _size; | |
void* _buffer; | |
void* _offset; | |
void* do_allocate(size_t bytes, size_t alignment) override { |
OlderNewer