- 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.
This file contains hidden or 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
| """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: |
This file contains hidden or 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 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| #!/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 |
This file contains hidden or 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
| #! /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); |
This file contains hidden or 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 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() |
This file contains hidden or 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 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 |
This file contains hidden or 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 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): |
This file contains hidden or 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
| 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. | |
| // |
NewerOlder