Skip to content

Instantly share code, notes, and snippets.

View mohsenk's full-sized avatar
🎯
Focusing

Mohsen Karimi mohsenk

🎯
Focusing
View GitHub Profile
@mohsenk
mohsenk / nginx-tuning.md
Created March 27, 2018 11:14 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@mohsenk
mohsenk / DNSPromise.java
Created August 24, 2017 07:55 — forked from etiennecarriere/DNSPromise.java
Usage of Listener on DNSResolver
import java.net.InetSocketAddress;
import io.netty.channel.AddressedEnvelope;
import io.netty.handler.codec.dns.DnsRecord;
import io.netty.handler.codec.dns.DnsResponse;
import io.netty.handler.codec.dns.DnsSection;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
@mohsenk
mohsenk / .gitignore
Created March 13, 2016 19:44 — forked from karmi/.gitignore
`tail -f` in Node.js and WebSockets
.DS_Store
*.log
tmp/
@mohsenk
mohsenk / distance.sql
Created February 25, 2016 16:12 — forked from Usse/distance.sql
MySQL calculate distance between two latitude/longitude coordinates
CREATE FUNCTION `lat_lng_distance` (lat1 FLOAT, lng1 FLOAT, lat2 FLOAT, lng2 FLOAT)
RETURNS FLOAT
DETERMINISTIC
BEGIN
RETURN 6371 * 2 * ASIN(SQRT(
POWER(SIN((lat1 - abs(lat2)) * pi()/180 / 2),
2) + COS(lat1 * pi()/180 ) * COS(abs(lat2) *
pi()/180) * POWER(SIN((lng1 - lng2) *
pi()/180 / 2), 2) ));
END
@mohsenk
mohsenk / Application.java
Last active September 9, 2015 09:31 — forked from fehmicansaglam/Application.java
Accept range header and write a partial content to the response with Play! Framework.
public static void downloadFile(final Long fileId) throws IOException {
response.setHeader("Accept-Ranges", "bytes");
notFoundIfNull(fileId);
File underlyingFile = ... //load file
String fileName = ...//name of the file
Header rangeHeader = request.headers.get("range");
if (rangeHeader != null) {
throw new PartialContent(underlyingFile, fileName);