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::sync::Arc; | |
use tokio::sync::Mutex; | |
use tokio::net::TcpListener; | |
use tokio::sync::mpsc; | |
use tokio::io::{AsyncReadExt, AsyncWriteExt}; | |
use slotmap::{DenseSlotMap, DefaultKey}; | |
use tokio::select; | |
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
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
const {Provider: AudioContextProvider, Consumer: AudioConsumer} = React.createContext(); | |
class AudioProvider extends Component { | |
static propTypes = { | |
children: PropTypes.arrayOf(PropTypes.node).isRequired, | |
} |
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
import contextlib | |
@contextlib.contextmanager | |
def bulk_object_creator(limit=100): | |
""" | |
Allows creation of model objects in bulk, intelligently not using too much memory. | |
with bulk_object_creator() as foo_creator: | |
for i in range(100000): |
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
from django.core.cache import cache | |
class RateLimiter(object): | |
def __init__(self, timeout, max_failures): | |
self.timeout = timeout | |
self.max_failures = max_failures | |
def get_key(self, t): | |
return ':'.join(str(s) for s in t) |
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
def sa_to_django(model, row, table=None): | |
""" | |
Constructs a Django model from a sqlalchemy result row. We could just fetch | |
the django model by id, but that'd several queries for each row of the | |
report. | |
XXX: Does not handle _meta.state.adding (maybe it should?), so don't try to | |
save the model. | |
""" |
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 EmptyCase #-} | |
import Data.Void | |
import Control.Applicative | |
import Control.Monad.Trans | |
import Control.Monad | |
import Control.Monad.Writer | |
import System.IO | |
import qualified Data.ByteString as B |
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
""" | |
Provides all the settings that are required to get COMPRESS_OFFLINE mode | |
working for django-compressor, just import everything from this file into your | |
settings and you will have turned on the offline compress mode. | |
If you wish to test it on your local setup, you can import it in your local | |
settings file. | |
# myproject/settings.py | |
from .settings_compress_offline import * |
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 GADTs, StandaloneDeriving, TypeOperators, ExistentialQuantification, EmptyCase #-} | |
import Data.Type.Equality | |
import Data.Void | |
data UTerm = UTrue | |
| UFalse | |
| UIf UTerm UTerm UTerm | |
| UZero | |
| USucc UTerm |
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 GADTs, ExistentialQuantification, TypeOperators, StandaloneDeriving #-} | |
import Data.Type.Equality | |
import Text.Read | |
data Renderer a b where | |
-- Lifts a normal function to a Renderer. The String is just a label | |
-- to see what's going on. | |
Lift :: String -> (a -> b) -> Renderer a b |
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
tmpd = do | |
tmp <- var $ glob "/tmp/tmp/" | |
today <- function $ cmd "date" ["+%F"] | |
when_ (not_ $ dirExists tmp) $ mkdir tmp | |
cd tmp | |
i <- var $ lit "1" | |
dir <- var $ today | |
while_ (dirExists dir) $ do | |
set i $ readVar i + 1 | |
set dir $ today <> lit "." <> readVar i |
NewerOlder