Skip to content

Instantly share code, notes, and snippets.

View d3banjan's full-sized avatar

Debanjan d3banjan

View GitHub Profile
@d3banjan
d3banjan / test_rwkv_tokenizer.py
Created March 14, 2026 20:00
Tests for RWKV World Tokenizer: 3 bug fixes (phantom token, greedy match, decode mojibake) + Rust fast tokenizer parity
"""Tests for RWKV World Tokenizer — bug fixes and fast tokenizer parity.
Covers:
- 3 bug fixes in hf_rwkv_tokenizer.py (PR #3)
- Rust fast tokenizer parity (PR #2)
Requirements:
pip install transformers rwkv-tokenizer pytest
Run:
@d3banjan
d3banjan / main.py
Created October 9, 2023 13:40
skyscraper puzzle
# Import required modules
from itertools import permutations, product, accumulate
from collections import defaultdict
import pprint
# Function to calculate the visibility score using differences between adjacent maximum heights
def visibility_score_with_diff(perm):
max_heights = list(accumulate(perm, func=max))
differences = [b - a for a, b in zip(max_heights[:-1], max_heights[1:])]
score = sum(diff != 0 for diff in differences) + 1
curl -L "https://raw.githubusercontent.com/noSenseOfDangerous/PythonDesignPattern/master/factoryPattern_01/data/donut.json" -o donut.json
# % Total % Received % Xferd Average Speed Time Time Time Current
# Dload Upload Total Spent Left Speed
# 100 2895 100 2895 0 0 14532 0 --:--:-- --:--:-- --:--:-- 14547
ls -lh .
# total 4,0K
# -rw-r--r-- 1 debanjan debanjan 2,9K 12. Mär 15:02 donut.json
wc -l *
# 129 donut.json
jq '.' donut.json
@d3banjan
d3banjan / yaml_OrderedDict.py
Created October 22, 2018 11:02 — forked from oglops/yaml_OrderedDict.py
write to and load from yaml file with OrderedDict
#!/usr/bin/env python
try:
# for python newer than 2.7
from collections import OrderedDict
except ImportError:
# use backport from pypi
from ordereddict import OrderedDict
import yaml
@d3banjan
d3banjan / download-chunker.sh
Last active September 15, 2018 09:05
download large files in chunks
#! /bin/bash
LARGE_FILE_URL="http://vatic2.stanford.edu/stanford_campus_dataset.zip"
APPROX_SIZE=`echo "69*1024*1024*1024"| bc`
CHUNKSIZE=`echo "128*1024*1024" | bc`
NCHUNKS=`echo "1+ (($APPROX_SIZE)/($CHUNKSIZE))" | bc`
STARTCHUNK="1"
OUTDIR="/media/debanjan/xxx"
OUTFILE="stanford_campus_dataset.zip"
SLEEP_INTERVAL="10"
for ichunk in $(seq -f '%05g' 1 $NCHUNKS);
@d3banjan
d3banjan / notes.md
Last active April 9, 2018 11:53
ankhi - setting up the code

what is a conda environment?

  • in python or R, we need to install packages to add functionality to our programs so that we do not have to program everything by ourselves.
  • sometimes as the version of a package evolves, it might change behaviour. As a result of this, the code that we wrote two years ago, might not run out of the box anymore.
  • even if we do get our code to run properly, it is truly a mightmare to send our code to others and expect them to run it.
  • python environments are a solution intended for the above scenarios, where an environment can be trusted to maintain a specfic version of a packages, even if the packages are upgraded. It also becomes easy to send our code to someone else, where they can install the software mentioned in our project directory called requirements.txt.
  • conda environments offer the same feature as above, but for both python and R.
@d3banjan
d3banjan / demo.py
Created April 7, 2018 15:33
medium-dscookiecutter-example snip02
import os, click, logging
@click.command()
@click.option('--option',default='default')
@click.argument('string',nargs=-1)
def main(option,string):
print("the argument(s) is(are) \"{}\" with an optional modifier {}".format(",".join(string),option))
if __name__=='__main__':
main()
@d3banjan
d3banjan / demo.py
Created April 7, 2018 15:32
medium-dscookiecutter-example snip01
import os
from dotenv import find_dotenv,load_dotenv
print(find_dotenv())
#>/home/debanjan/git-projects/medium-dscookiecutter-example/src/.env
print(load_dotenv(find_dotenv()))
#>True
keys = "CONFIG_PATH DOMAIN EMAIL".split()
for key in keys:
print(key,os.getenv(key))
#>CONFIG_PATH /home/debanjan/.config/foo
@d3banjan
d3banjan / demo.py
Last active April 7, 2018 15:54
medium-dscookiecutter-example snip03
import os, click, logging
@click.group()
def meta_command():
pass
@click.command()
@click.option('--option',default='default')
@click.argument('string',nargs=-1)
def first(option,string):
module ConstrainedTypes =
open System
// General hints on defining types with constraints or invariants
//
// Just as in C#, use a private constructor
// and expose "factory" methods that enforce the constraints
//
// In F#, only classes can have private constructors with public members.
//