Skip to content

Instantly share code, notes, and snippets.

@Mokosha
Mokosha / afrp.rs
Created September 2, 2020 07:30
Arrowized FRP in Rust
struct Reactive<'a, A, B> { next: Box<dyn 'a + FnOnce(A) -> (B, Reactive<'a, A, B>)> }
impl<'a, A, B> Reactive<'a, A, B> {
fn new<F>(f: F) -> Reactive<'a, A, B> where F : 'a + FnOnce(A) -> (B, Reactive<'a, A, B>) {
Reactive { next: Box::new(f) }
}
fn pure<F>(f: F) -> Reactive<'a, A, B> where F : 'a + Fn(A) -> B {
Reactive {
next: Box::new(|x| (f(x), Reactive::pure(f)))
@Mokosha
Mokosha / cvt.cpp
Created February 13, 2016 21:59
Conversion from RGB 565 to YCoCg 667
void rgb565_to_ycocg667(const int8_t *in, int8_t *out) {
int8_t r = in[0];
int8_t g = in[1];
int8_t b = in[2];
assert(0 <= r && r < 32);
assert(0 <= g && g < 64);
assert(0 <= b && b < 32);
out[1] = r - b;
uint16 colors[4][4];
uint32 result[3];
memset(result, 0, sizeof(result));
// ...
for (int i = 15; i >= 0; i--){ // danggers of infinite loops using unsigned intergers
for (int ch = 0; ch < 3; ++ch) {
src\sampler_renderer.rs:201:36: 201:81 error: the trait `core::marker::Sync` is not implemented for the type `alloc::rc::Rc<shape::loopsubdiv::SDFace>` [E0277]
src\sampler_renderer.rs:201 unsafe { scope.execute(move || run_task(data, i, num_tasks)); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\sampler_renderer.rs:201:36: 201:81 help: run `rustc --explain E0277` to see a detailed explanation
src\sampler_renderer.rs:201:36: 201:81 note: `alloc::rc::Rc<shape::loopsubdiv::SDFace>` cannot be shared between threads safely
src\sampler_renderer.rs:201:36: 201:81 note: required because it appears within the type `alloc::raw_vec::RawVec<alloc::rc::Rc<shape::loopsubdiv::SDFace>>`
src\sampler_renderer.rs:201:36: 201:81 note: required because it appears within the type `collections::vec::Vec<alloc::rc::Rc<shape::loopsubdiv::SDFace>>`
src\sampler_renderer.rs:201:36: 201:81 note: required because it appears within the type `shape::loop
@Mokosha
Mokosha / ilhack.h
Created November 20, 2015 22:11
VS2012 Hack workaround
// !HACK! Stupid VS 2012 doesn't support initializer lists yet...
#define INIT_VEC(Ty, ...) \
[] { \
const Ty arr_Ty[] = { __VA_ARGS__ }; \
std::vector<Ty> vec_Ty(arr_Ty, arr_Ty + sizeof(arr_Ty) / sizeof(arr_Ty[0])); \
return std::move(vec_Ty); \
}()
// std::vector<int> foo = INIT_VEC(int, 2, 3, 4);

I recently watched the pilots to both The Good Wife and Supergirl, two shows that take very different approaches to feminism. In Supergirl, feminism is front and center. From the get-go, Kara is showing, and often saying, that women ("girls") can be just as heroic as men. For the first time, we get superheroes that can serve as role models for young women, and honestly, that's a breath of fresh air. The show certainly likes to talk the talk.

With all of it's well intentions, feminism in Supergirl seems to be modeled around a severe amount of imposter syndrome within the first half of the episode only to be reconciled after a heart to heart with the protagonist's sister. While this may have been an artifact of having to drive the plot in the pilot forward, it still screams of Supergirl needing permission to be a hero. The two people that give it to her

@Mokosha
Mokosha / gist:9b196b35f5858fc8fef0
Created May 14, 2015 08:58
Stop and remove all running docker containers
for i in `docker ps -a | tail -n $((\`docker ps -a | wc -l\` - 1)) | awk '{ print $1 }'`; do docker stop $i && docker rm $i; done
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
data FooRep = Foo deriving (Show)
type Foo a = FooRep
data V2 a = V2 a a deriving (Show)
data V3 a = V3 a a a deriving (Show)
class Foo a where
foo :: a -> String
instance Foo Int where
foo _ = "Int"
instance Foo Char where
foo _ = "Char"
f :: Foo a => a -> String
@Mokosha
Mokosha / WireTest.hs
Last active August 29, 2015 14:01
Leaking Netwire Program
module Main where
import Control.Wire
mkWire :: (Num b, HasTime t s, Show b, Monad m) => b -> Wire s () m a b
mkWire x = ((pure x) &&& (periodic 2) >>> Control.Wire.until) --> (mkWire (x + 1))
main :: IO ()
main = testWire clockSession_ (mkWire 3)