Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Working from home

Anil Wadghule anildigital

:octocat:
Working from home
View GitHub Profile
View uber_denial_by_dns_test.exs
# This is the proper BEAM test for https://github.com/uber/denial-by-dns. The Erlang test in that repo is sequential
# (https://github.com/uber/denial-by-dns/blob/b809cc561a691d9d6201d06d38d06c33c9c9f9ec/erlang-httpc/main.erl)
# which is not consistent with the test description (https://github.com/uber/denial-by-dns/tree/b809cc561a691d9d6201d06d38d06c33c9c9f9ec#how-it-works)
# and also differs from e.g. go test in the same repo which issues requests concurrently.
#
# Consequently, the conclusion in that repo as well as the original article (https://eng.uber.com/denial-by-dns/) is incorrect.
# A properly written Erlang test would pass, as demonstrated by this Elixir script.
#
# This code performs a slightly refined and a correct version of that tests in Elixir:
#
@henrik
henrik / each_in_thread_pool.rb
Last active Feb 2, 2021
Run a block on a list of things in a limited number of concurrent threads. Mostly for the fun of it – there are more featureful libs like https://github.com/grosser/parallel.
View each_in_thread_pool.rb
# Lets you call a block for each item in a list, just like `each`.
# But instead of running serially, it runs in a limited number of parallel threads.
# This is useful when you don't just want one thread per item, e.g. to avoid rate limiting or network saturation.
class EachInThreadPool
def self.call(inputs, pool_size:, &block)
queue = Queue.new
inputs.each { queue << _1 }
pool_size.times.map {
@apboobalan
apboobalan / elixir_typespec.md
Created Sep 4, 2020
Gist about typespecs in Elixir
View elixir_typespec.md
  • To define type spec for a functions @spec function_name(arg_1_type, arg_2_type) :: return_type
  • To define new type@type new_type_name :: existing_type
  • To document type place @typedoc """ description """ above type definition.
  • We can create product types such as lists, tuples and maps using their own syntax with members being the types.
  • Eg. Product types
@type statuses :: [atom]

@type number_with_remark :: {number, String.t}
@apboobalan
apboobalan / RealTimePhoenixGist.md
Created Sep 1, 2020
Key concepts to remember from real time phoenix book.
View RealTimePhoenixGist.md
  • Scalability triangle
    • Performance, maintenance, cost
  • WS lifecycle
    • inspect ws inside browser dev tools
    • Initial call is made using HTTP and then 101 protocol switch response is received and the connection is upgraded to ws
    • Optional heartbeat messages are used in check connection.
    • Phoenix pings server every 30 seconds.
    • Server will close connection if it doesn't receive ping within 60 seconds.
    • use wss:// for security.
    • ws doesn't follow CORS policy.
@jswny
jswny / Flexible Dockerized Phoenix Deployments.md
Last active Feb 28, 2021
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.
View Flexible Dockerized Phoenix Deployments.md

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

View quick-tips-optimizing-jvm.md

Quick Tips for Fast Code on the JVM

I was talking to a coworker recently about general techniques that almost always form the core of any effort to write very fast, down-to-the-metal hot path code on the JVM, and they pointed out that there really isn't a particularly good place to go for this information. It occurred to me that, really, I had more or less picked up all of it by word of mouth and experience, and there just aren't any good reference sources on the topic. So… here's my word of mouth.

This is by no means a comprehensive gist. It's also important to understand that the techniques that I outline in here are not 100% absolute either. Performance on the JVM is an incredibly complicated subject, and while there are rules that almost always hold true, the "almost" remains very salient. Also, for many or even most applications, there will be other techniques that I'm not mentioning which will have a greater impact. JMH, Java Flight Recorder, and a good profiler are your very best friend! Mea

@djg
djg / reading-list.md
Last active Feb 4, 2021
Fabian's Recommened Reading List
View reading-list.md
@torch2424
torch2424 / systemDAsUser.service
Last active Jan 5, 2021
Run a systemd service as a user
View systemDAsUser.service
# How to create systemd services: http://neilwebber.com/notes/2016/02/10/making-a-simple-systemd-file-for-raspberry-pi-jessie/
# Digital ocean on a mongodb service: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04
[Unit]
Description=Run SystemD as users
After=network.target
[Service]
Type=simple
User=[USER HERE]
WorkingDirectory=[USER HOME]
@rissem
rissem / app.js
Created Jan 5, 2017
html5/node.js video capture and upload
View app.js
/* global require */
const multipart = require('connect-multiparty')
const multipartMiddleware = multipart()
const path = require('path')
const os = require('os')
const fs = require('fs')
var express = require('express')
var app = express()
View Effective_Engineer.md

FWIW: I'm not the author of the content presented here (which is an outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?