Skip to content

Instantly share code, notes, and snippets.

Avatar

Rajeev Singh callicoder

View GitHub Profile
@tasdikrahman
tasdikrahman / haproxy-allow-whitelisted-IPs.cfg
Created May 5, 2019
HAproxy config (/etc/haproxy/haproxy.cfg) for kingsly to allow only whitelisted IP's for a backend.
View haproxy-allow-whitelisted-IPs.cfg
frontend kingsly-frontend
...
...
acl ALLOW_SRC src -f /etc/haproxy/include/allow-ips.lst
http-request deny if !ALLOW_SRC
...
...
default_backend kingsly
@ArsalRaza
ArsalRaza / VideoUtils.java
Last active Jan 11, 2022
Extract Audio from Video, Mute Video, Crop Video from start, Crop Video from end Android MediaMuxer - JAVA
View VideoUtils.java
import android.annotation.SuppressLint;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.MediaMetadataRetriever;
import android.media.MediaMuxer;
import android.util.Log;
import java.io.IOException;
import java.nio.ByteBuffer;
View 0-rate-limiters.md

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.

@javierarques
javierarques / sticky.js
Last active Mar 5, 2021
Sticky Sideabr With Vanilla Javascript. Detects scroll and set fixed the element. Live example: http://codepen.io/javiarques/pen/vKdgjR
View sticky.js
// Sticky Nav Component
var Sticky = (function() {
'use strict';
var CSS_CLASS_ACTIVE = 'is-fixed';
var Sticky = {
element: null,
position: 0,
addEvents: function() {
@harlow
harlow / golang_job_queue.md
Last active Jan 16, 2022
Job queues in Golang
View golang_job_queue.md
@sayan801
sayan801 / Extract Audio from Video Using MediaMuxer
Created Oct 7, 2014
Extract Audio from Video Using MediaMuxer
View Extract Audio from Video Using MediaMuxer
private boolean cloneMediaUsingMuxer(String srcMedia, String dstMediaPath,
int expectedTrackCount, int degrees) throws IOException {
// Set up MediaExtractor to read from the source.
//AssetFileDescriptor srcFd = mResources.openRawResourceFd(srcMedia);
MediaExtractor extractor = new MediaExtractor();
extractor.setDataSource(srcMedia);
int trackCount = extractor.getTrackCount();
//assertEquals("wrong number of tracks", expectedTrackCount, trackCount);
// Set up MediaMuxer for the destination.
MediaMuxer muxer;
@zziuni
zziuni / stuns
Created Sep 18, 2012
STUN server list
View stuns
# source : http://code.google.com/p/natvpn/source/browse/trunk/stun_server_list
# A list of available STUN server.
stun.l.google.com:19302
stun1.l.google.com:19302
stun2.l.google.com:19302
stun3.l.google.com:19302
stun4.l.google.com:19302
stun01.sipphone.com
stun.ekiga.net