Skip to content

Instantly share code, notes, and snippets.

View emptymalei's full-sized avatar
📡
sending EM waves to Mars

LM emptymalei

📡
sending EM waves to Mars
View GitHub Profile
@maedoc
maedoc / µrwkv.py
Last active January 24, 2024 15:09
Another short take on RWKV, towards use with time series
import numpy as np
import torch
class MyModule(torch.nn.Module):
def add_param(self, key, shape):
val = torch.randn(*shape)/np.prod(shape)
setattr(self, key, torch.nn.Parameter(val))
# First, some imports:
import numpy as np
from darts.utils import timeseries_generation as tg
np.random.seed(42)
LENGTH = 3 * 365 # 3 years of daily data
# Melting: a sine with yearly periodicity and additive white noise
melting = (tg.sine_timeseries(length=LENGTH,
@grantmwilliams
grantmwilliams / iter_parquet.py
Created June 27, 2021 12:45
Pyarrow iter_batches as python native iterable
import s3fs
import pyarrow as pa
import pyarrow.parquet as pq
from itertools import chain
from typing import Tuple, Any
def iter_parquet(s3_uri: str, columns = None, batch_size=1_000) -> Tuple[Any]:
@svpino
svpino / on-start.sh
Last active June 23, 2023 11:34
SageMaker Notebook Instance - Lifecycle configuration - New Conda Environment
#!/bin/bash
set -e
sudo -u ec2-user -i <<'EOF'
ENVIRONMENT=python38
VERSION=3.8
conda create -y -n "$ENVIRONMENT" python="$VERSION" tensorflow-gpu numpy opencv pandas pyyaml
@nkhitrov
nkhitrov / logger.py
Last active March 27, 2024 07:15
Configure uvicorn logs with loguru for FastAPI
"""
WARNING: dont use loguru, use structlog
https://gist.github.com/nkhitrov/38adbb314f0d35371eba4ffb8f27078f
Configure handlers and formats for application loggers.
"""
import logging
import sys
from pprint import pformat
@Treeki
Treeki / TurnipPrices.cpp
Last active February 21, 2024 16:01
AC:NH turnip price calculator
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// munged from https://github.com/simontime/Resead
namespace sead
{
class Random
{
@cmod
cmod / hugofastsearch.md
Last active March 22, 2024 07:02 — forked from eddiewebb/readme.md
Fast, instant client side search for Hugo static site generator

Super fast, keyboard-optimized, client side Hugo search

This is a fork of and builds upon the work of Eddie Webb's search and Matthew Daly's search explorations.

It's built for the Hugo static site generator, but could be adopted to function with any json index compatible with Fuse fuzzy search library.

To see it in action, go to craigmod.com and press CMD-/ and start typing.

Fast Search

class Person extends IdyllModel
belongs_to :working_population
define_attribute :stress, type: integer, min: 0, max: 100, init: random
define_attribute :environment, type: enum, ['high income', 'low income', 'normal']
define_attribute :group, type: classification, |model| => { case model.stress; when 50..100: "high risk"; when 0..49: "low risk" }
def next_step
self.stress += 5 if self.environment == "high income"
self.stress -= 5 if self.environment == "low income"
@lislis
lislis / event.md
Last active October 5, 2021 11:52
Hugo ical template

title: "Event title" slug: event-title date: "2020-03-02T19:30:00+01:00" summary: "the standard says this should be less than 75 characters!" end: "2020-03-02T22:00:00+01:00" location: "Event location if known" organizer: name: "Your name" email: "your@email.com"

@achinta
achinta / pyspark_fill.py
Last active January 27, 2023 14:40
Forward Fill in Pyspark
import pyspark.sql.functions as F
from pyspark.sql import Window
df = spark.createDataFrame([
('d1',None),
('d2',10),
('d3',None),
('d4',30),
('d5',None),
('d6',None),