Skip to content

Instantly share code, notes, and snippets.

View santhosh77h's full-sized avatar
🦀
hello world!!

santhosh H santhosh77h

🦀
hello world!!
View GitHub Profile
@gbzarelli
gbzarelli / mongo-docker-compose.yml
Last active February 29, 2024 17:24
Initializing mongo db in docker-compose with init script
version: '3.8'
services:
# Database - Mongo DB
mongo:
image: mongo
environment:
MONGO_INITDB_ROOT_USERNAME: helpdev
MONGO_INITDB_ROOT_PASSWORD: 123456
@Mefistophell
Mefistophell / RUST.MD
Last active April 16, 2024 17:32
How to Compile a Rust Program on Mac for Windows

Question: I want to compile my Rust source code for the Windows platform but I use macOS.

Solution:

  1. Install target mingw-w64: brew install mingw-w64
  2. Add target to rustup: rustup target add x86_64-pc-windows-gnu
  3. Create .cargo/config
  4. Add the instructions below to .cargo/config
[target.x86_64-pc-windows-gnu]
@jibwa
jibwa / gist:6eb68778a22957fa9dbbb87b9cd2a4e3
Created April 16, 2017 03:17
Plain es6 promise solution to async with followup and collecting args for response
Promise.all([
Product.create({
name: 'MacbookPro',
qty: 1232213,
price: 10000.
}),
Order.findOne({
orderNumber: 123
})
])

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.

@AshikNesin
AshikNesin / react-file-upload.js
Created February 2, 2017 06:46
Simple React File Upload
import React from 'react'
import axios, { post } from 'axios';
class SimpleReactFileUpload extends React.Component {
constructor(props) {
super(props);
this.state ={
file:null
}
@ludwig
ludwig / logger.js
Created August 25, 2016 10:10 — forked from transitive-bullshit/logger.js
winston logger with filename:linenumber
// NOTE: this adds a filename and line number to winston's output
// Example output: 'info (routes/index.js:34) GET 200 /index'
var winston = require('winston')
var path = require('path')
var PROJECT_ROOT = path.join(__dirname, '..')
var logger = new winston.logger({ ... })
// this allows winston to handle output from express' morgan middleware
anonymous
anonymous / index.html
Created March 18, 2016 11:14
JS Bin // source http://jsbin.com/vafove
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<style id="jsbin-css">
.ng-modal-overlay {
/* A dark translucent div that covers the whole screen */
position:absolute;
@leommoore
leommoore / mongodb_ssl_with_letsencrypt.md
Last active August 16, 2022 17:35
MongoDB 3.2.x SSL with Letsencrypt

MongoDB 3.2.x SSL with Letsencrypt

Letsencrypt is an initative which aims to increase the use of encryption for websites. It basically allows people to apply for free certificates provided that they prove the they control the requested domain. We will look at the what is needed to secure your MongoDB installation. For more details on setting up a MongoDB server see MongoDB 3.2.x.

Set the hostname

We sould to set the hostname to match the name of the certificate we are going to optain.

sudo hostname mongo0.example.com

Then update the hostname file to set the server name permanently.

@leommoore
leommoore / mongodb_3.2.x_replica_sets_on_aws_ec2.md
Last active March 15, 2022 22:28
MongoDB 3.2.x Replica Sets on AWS EC2

#MongoDB 3.2.x Replica Sets on AWS EC2 A MongoDB replica set provides a mechanism to allow for a reliable database services. The basic replica set consists of three servers, a primary, a secondary and an arbitrator. The primary and secondary both hold a copy of the data. The arbitrator is normally a low spec server which just monitors the other servers and help with the failover process. In production, there can be more than three servers.

To setup mongo as a replica set on Amazon Web Services EC2 you need to first setup a security group with ssh on port 22 and mongodb on port 27017. You then need to create three servers. Select Ubuntu 14.04 LTS x64 and a micro (or bigger depending on your database size, ideally you should have enough memory to match your database size) instance for the primary and secondary and a nano instance for the arbitrator.

##Adjust the File System on each Server The operating system by default will update the last access time on a file. In a high data throughput database application

@marcoberri
marcoberri / downgrade_Mongodb_replica_to_standalone.txt
Created February 2, 2016 11:12
Migrate MongoDB ReplicaSet to single MongoDB Node
mongoserver:PRIMARY> rs.status();
{
"set" : "mongoserver",
"date" : ISODate("2016-02-02T10:47:07.510Z"),
"myState" : 1,
"members" : [
{
"_id" : 3,
"name" : "192.168.1.10:37017",
"health" : 1,