Skip to content

Instantly share code, notes, and snippets.

@jboner
jboner / latency.txt
Last active May 4, 2024 21:16
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@lewtun
lewtun / sft_trainer.py
Last active April 27, 2024 21:28
Fine-tuning Mistral 7B with TRL & DeepSpeed ZeRO-3
# This is a modified version of TRL's `SFTTrainer` example (https://github.com/huggingface/trl/blob/main/examples/scripts/sft_trainer.py),
# adapted to run with DeepSpeed ZeRO-3 and Mistral-7B-V1.0. The settings below were run on 1 node of 8 x A100 (80GB) GPUs.
#
# Usage:
# - Install the latest transformers & accelerate versions: `pip install -U transformers accelerate`
# - Install deepspeed: `pip install deepspeed==0.9.5`
# - Install TRL from main: pip install git+https://github.com/huggingface/trl.git
# - Clone the repo: git clone github.com/huggingface/trl.git
# - Copy this Gist into trl/examples/scripts
# - Run from root of trl repo with: accelerate launch --config_file=examples/accelerate_configs/deepspeed_zero3.yaml --gradient_accumulation_steps 8 examples/scripts/sft_trainer.py
@Vestride
Vestride / encoding-video.md
Last active April 24, 2024 09:59
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus
@seratch
seratch / README.md
Last active March 31, 2024 13:43
Sign in with Slack - the simplest example

You can run this app by following the steps below:

Set up your Slack app

  • Create a new Slack app from https://api.slack.com/apps?new_app=1
  • Go to OAuth & Permissions
    • Add identity.basic & identity.email to User Token Scopes
    • Add OAuth Redirect URL
  • Go to Basic Information
  • Grab the Client ID & Client Secret in the page
@karmi
karmi / git-hosting-apache.conf
Created July 21, 2010 07:43
Configuration for hosting Git repositories with Apache 2.x
# ----------------------------------------------------------
# Configuration for hosting Git repositories with Apache 2.x
# ----------------------------------------------------------
#
# This setup provides "dual URLS", where URL like <http://git.example.com/my_repository.git>
# loads Gitweb in the browser and the same URL can be used in commands like `git clone` and `git remote add`.
# It was compiled from some sources on the internet and further customized/tuned.
#
# Please see documentation for:
#

Stackoverflow to Elasticsearch

This script will load any stackoverflow site from the XML dump (retrievable at https://archive.org/details/stackexchange via torrent) into Elasticsearch.

To use just call:

python load_stack.py PATH
@marianogappa
marianogappa / backpressure.go
Created December 4, 2016 04:53
Example backpressure implementation in Go
/*
This snippet is an example of backpressure implementation in Go.
It doesn't run in Go Playground, because it starts an HTTP Server.
The example starts an HTTP server and sends multiple requests to it. The server starts denying
requests by replying an "X" (i.e. a 502) when its buffered channel reaches capacity.
This is not the same as rate-limiting; you might be interested in https://github.com/juju/ratelimit
or https://godoc.org/golang.org/x/time/rate.
@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article &lt; ActiveRecord::Base
@qwesda
qwesda / hash_large_file.html
Last active September 22, 2022 00:52
asmcrypto - example - hash large file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Hash large File Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/asmCrypto/0.22.0/asmcrypto.min.js"></script>
<script type="text/javascript" language="javascript">
function on_hash_done(hash, time_elapsed_seconds) {
document.getElementById('progress').innerText = '';
@karmi
karmi / .gitignore
Created March 16, 2012 16:09
Bootstrap, install and configure ElasticSearch with Chef Solo
.DS_Store
Gemfile.lock
*.pem
node.json
tmp/*
!tmp/.gitignore