Skip to content

Instantly share code, notes, and snippets.

View singhai0's full-sized avatar
😩
EHOSTUNREACH

Mridul Singhai singhai0

😩
EHOSTUNREACH
  • San Francisco, CA
View GitHub Profile
@dbieber
dbieber / fastbook.py
Last active August 10, 2023 18:13
fastbook speeds up the silence in audiobooks, and can speed up the non-silence too
"""Performs automatic speed edits to audio books.
Example usage:
Assuming you have an audiobook book.aax on your Desktop:
1. Convert it to wav:
ffmpeg -i ~/Desktop/book.aax ~/Desktop/book.wav
2. Adjust the speed:
@gaearon
gaearon / modern_js.md
Last active April 18, 2024 15:01
Modern JavaScript in React Documentation

If you haven’t worked with JavaScript in the last few years, these three points should give you enough knowledge to feel comfortable reading the React documentation:

  • We define variables with let and const statements. For the purposes of the React documentation, you can consider them equivalent to var.
  • We use the class keyword to define JavaScript classes. There are two things worth remembering about them. Firstly, unlike with objects, you don't need to put commas between class method definitions. Secondly, unlike many other languages with classes, in JavaScript the value of this in a method [depends on how it is called](https://developer.mozilla.org/en-US/docs/Web/Jav
# Ideally, we would manage async access to stdin/stdout/stderr *without*
# setting them to non-blocking mode, because that can break other processes.
# (See https://github.com/python-trio/trio/issues/174 for much more detail.)
# Of course we can call read/write in a separate thread, but then we lose
# cancellation support.
# This file demonstrates a weird hack to make blocking read/write cancellable,
# and thus at least theoretically possible to integrate into Trio as ordinary
# first-class operations.
@dbechrd
dbechrd / mg
Last active April 20, 2023 16:45
#!/bin/bash
DEBUG=0
VERBOSE=0
CMDS="args|b|br|co|db|nb|pb|pr|rbm|web"
BRANCH_PREFIX="dlb-"
BRANCH_URL_SAFE=""
REPO=`git remote -v | grep -m 1 "(push)" | sed -E "s/.*github\.com[:/](.*)(\.git| ).*/\1/"`

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

@fchollet
fchollet / classifier_from_little_data_script_3.py
Last active September 13, 2023 03:34
Fine-tuning a Keras model. Updated to the Keras 2.0 API.
'''This script goes along the blog post
"Building powerful image classification models using very little data"
from blog.keras.io.
It uses data that can be downloaded at:
https://www.kaggle.com/c/dogs-vs-cats/data
In our setup, we:
- created a data/ folder
- created train/ and validation/ subfolders inside data/
- created cats/ and dogs/ subfolders inside train/ and validation/
- put the cat pictures index 0-999 in data/train/cats
diff --git a/diesel/src/lib.rs b/diesel/src/lib.rs
index 28c60a3..18225b2 100644
--- a/diesel/src/lib.rs
+++ b/diesel/src/lib.rs
@@ -3,6 +3,7 @@
//! found in the README.
#![deny(warnings)]
#![cfg_attr(feature = "unstable", feature(specialization))]
+#![cfg_attr(all(test, feature = "unstable"), feature(test))]
@gene1wood
gene1wood / 01_get_account_id_for_user_ec2instance_role_or_lambda.py
Last active November 9, 2022 16:40
Method to determine your AWS account ID using boto3 for either a user or an ec2 instance or lambda function
import boto3
print(boto3.client('sts').get_caller_identity()['Account'])
@patik
patik / how-to-squash-commits-in-git.md
Last active October 17, 2023 02:19
How to squash commits in git

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date: