Skip to content

Instantly share code, notes, and snippets.

Abu Ashraf Masnun masnun

Block or report user

Report or block masnun

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View asyncIterators.ts
class RangeIterator implements Iterator<number> {
constructor(private n: number, private to: number) {}
next(): IteratorResult<number> {
if (this.n <= this.to) {
return { done: false, value: this.n++ };
} else {
return { done: true, value: undefined };
}
}
}
View recovery.go
package middlewares
import (
"encoding/json"
"fmt"
"net/http"
)
func Recovery(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
View main.go
package main
import (
"encoding/json"
"github.com/masnun/gopher-and-rabbit"
"github.com/streadway/amqp"
"log"
"math/rand"
"time"
)
View main.go
package main
import (
"encoding/json"
"log"
"os"
gopher_and_rabbit "github.com/masnun/gopher-and-rabbit"
"github.com/streadway/amqp"
)
View chi_example.go
package main
import (
"encoding/json"
"net/http"
"github.com/go-chi/chi"
)
func main() {
View upload_to_s3.ts
import * as fs from "fs";
import * as AWS from "aws-sdk";
const BUCKET_NAME = "<<bucket name>>";
const IAM_USER_KEY = "<<user key>>";
const IAM_USER_SECRET = "<<user secret>>";
const s3bucket = new AWS.S3({
accessKeyId: IAM_USER_KEY,
secretAccessKey: IAM_USER_SECRET
View promise_with_timeout.js
function wait(signal, ms) {
return new Promise((res, rej) => {
const timeOut = setTimeout(() => {
console.log("I was called");
res("ok");
}, ms);
signal.catch(err => {
rej(err);
clearTimeout(timeOut);
View cancellable_promise_2.js
function wait(signal, ms) {
return new Promise((res, rej) => {
const timeOut = setTimeout(() => {
console.log("I was called");
res("ok");
}, ms);
signal.catch(err => {
rej(err);
clearTimeout(timeOut);
View cancellable_promise.js
function wait(ms) {
const ret = {};
const signal = new Promise((resolve, reject) => {
ret.cancel = () => {
reject(new Error("Promise was cancelled"));
};
});
ret.promise = new Promise((res, rej) => {
const timeOut = setTimeout(() => {
View README.md

How to use?

Install the dependencies from requirements.txt file.

pip install -r requirements.txt

Make the main.py file executable:

You can’t perform that action at this time.