Skip to content

Instantly share code, notes, and snippets.

View ethfun's full-sized avatar
🎯
Focusing

ING ethfun

🎯
Focusing
  • CN
View GitHub Profile
@digitaljhelms
digitaljhelms / gist:3099010
Created July 12, 2012 15:58
Squash the first two commits in a git repository's history

The scenario

Your repository has two commits:

$ git log --oneline
957fbfb No, I am your father.
9bb71ff A long time ago in a galaxy far, far away....
@arisetyo
arisetyo / openpage.js
Last active February 26, 2019 07:36
Webpage Screen Capture Using NodeJS and PhantomJS
var page = require('webpage').create();
var url = 'http://phantomjs.org/quick-start.html';
//SPECIFY VIEWPORT SIZE OF THE SCREENCAPTURE
page.viewportSize = {
width: 1280,
height: 900
};
@joseym
joseym / phantomjs-waitFor.js
Last active May 26, 2017 21:48
waitFor port for `phantomjs-node`
var async = require('async');
module.exports = waitFor;
/**
* waitFor port used with
* @see {@link https://github.com/ariya/phantomjs/blob/master/examples/waitfor.js}
* @see {@link https://github.com/sgentle/phantomjs-node}
* @callback testFx - Test function, will repeat until true or timeout limit is reached
* @callback onReady - Fires if/when `testFx` passes.
@jamtur01
jamtur01 / ladder.md
Last active February 17, 2025 09:09
Kickstarter Engineering Ladder
@syed
syed / aes_cbc_pkcs5_b64.go
Last active December 12, 2022 10:11
This simple program is to demonstrate encryption and decryption in golang using AES CBC with PKCS5Padding
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
b64 "encoding/base64"
"errors"
"fmt"
"log"
@LeCoupa
LeCoupa / redis_cheatsheet.bash
Last active April 17, 2025 11:09
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# Redis Cheatsheet
# All the commands you need to know
redis-server /path/redis.conf # start redis with the related configuration file
redis-cli # opens a redis prompt
# Strings.

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.

@grosscorporation
grosscorporation / Country Currency Codes JSON
Last active May 9, 2022 10:02
currency symol, name, plural, and decimal digits for all major and minor currencies
[
{
"USD" : {
"symbol" : "$",
"name" : "US Dollar",
"symbol_native" : "$",
"decimal_digits" : 2,
"rounding" : 0,
"code" : "USD",
"name_plural" : "US dollars"
@jasny
jasny / sha256-hmac.md
Last active December 12, 2023 12:32
Hashing examples in different languages

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

@kcak11
kcak11 / 0000.md
Last active March 2, 2025 12:30
AES/CBC/PKCS5PADDING - Java/Javascript (Encryption & Decryption)

AES/CBC/PKCS5PADDING - Java/Javascript (Encryption & Decryption)