Skip to content

Instantly share code, notes, and snippets.

@costrouc
costrouc / calculator.py
Created February 3, 2019 23:13
parser + ast + python source code translation
import ast
import astunparse
import sly
class CalculatorLexer(sly.Lexer):
tokens = { SYMBOL, NUMBER, PLUS, MINUS, TIMES, DIVIDE, LPAREN, RPAREN }
ignore = ' \t'
$ nix-shell -p nix-review --run "nix-review pr 64952"
$ git fetch --force https://github.com/NixOS/nixpkgs python-unstable:refs/nix-review/0 pu
ll/64952/head:refs/nix-review/1
From https://github.com/NixOS/nixpkgs
+ b8f84b24dee...e87daaa520e python-unstable -> refs/nix-review/0 (forced update)
+ 75bba3db2a5...1659822cd41 refs/pull/64952/head -> refs/nix-review/1 (forced update)
$ git worktree add /home/costrouc/.cache/nix-review/pr-64952/nixpkgs e87daaa520e086aafc48
9ed047f54712a1281a00
Preparing worktree (detached HEAD e87daaa520e)
HEAD is now at e87daaa520e python: scikit-learn: 0.20.3 -> 0.21.2
@costrouc
costrouc / shell.nix
Created July 17, 2019 18:12
Typical shell recipe
{ pkgs ? import <nixpkgs> { }, pythonPackages ? pkgs.python3Packages }:
let
pkgs = import (builtins.fetchTarball {
url = "https://github.com/costrouc/nixpkgs/archive/46976eff15c48713f2aa99bdbafa8229cb031262.tar.gz";
sha256 = "1q32jjv87n4dqchi00bj11bmy99pp72qdy3wy4c4fqxxchh63y38";
}) { };
pythonPackages = pkgs.python3Packages;
{ pkgs ? import <nixpkgs> { }, pythonPackages ? pkgs.python3Packages }:
let pythonEnv = pythonPackages.python.withPackages
(ps: with ps; [ numpy jupyterlab ]);
in {
shell = pkgs.mkShell {
buildInputs = [ pythonEnv ];
};
### Keybase proof
I hereby claim:
* I am costrouc on github.
* I am costrouc (https://keybase.io/costrouc) on keybase.
* I have a public key whose fingerprint is C2C0 41F0 21CB F58E 9BEB 3ED9 9ED5 9B0A B1EA F573
To claim this, I am signing this object:
import re
import dataclasses
@dataclasses.dataclass
class Token:
type: str
value: str
def tokenize(tokens, text):
regex = '|'.join([f'(?P<{name}>{pattern})' for name, pattern in tokens.items()])
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{"title": "Nebari Schema", "$ref": "#/definitions/ConfigSchema", "definitions": {"Prefect": {"title": "Prefect", "type": "object", "properties": {"enabled": {"title": "Enabled", "default": false, "type": "boolean"}, "image": {"title": "Image", "type": "string"}, "overrides": {"title": "Overrides", "default": {}, "type": "object"}, "token": {"title": "Token", "type": "string"}}, "additionalProperties": false}, "CDSDashboards": {"title": "CDSDashboards", "type": "object", "properties": {"enabled": {"title": "Enabled", "default": true, "type": "boolean"}, "cds_hide_user_named_servers": {"title": "Cds Hide User Named Servers", "default": true, "type": "boolean"}, "cds_hide_user_dashboard_servers": {"title": "Cds Hide User Dashboard Servers", "default": false, "type": "boolean"}}, "additionalProperties": false}, "DefaultImages": {"title": "DefaultImages", "type": "object", "properties": {"jupyterhub": {"title": "Jupyterhub", "default": "quay.io/nebari/nebari-jupyterhub:2023.5.1", "type": "string"}, "jupyterlab": {
  graph TD;
      A-->B;
      A-->C;
      B-->D;
      C-->D;
from rq import Queue
from redis import Redis
import tasks
import time
import contextlib
@contextlib.contextmanager
def timer(message: str):
start_time = time.time()