Skip to content

Instantly share code, notes, and snippets.

View anildigital's full-sized avatar
:octocat:

Anil Wadghule anildigital

:octocat:
View GitHub Profile
@PJUllrich
PJUllrich / big-o.md
Last active April 28, 2024 14:19
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for <= 32 elements, O(log n) for > 32 elements [2]
Deletion O(n) for <= 32 elements, O(log n) for > 32 elements
@myobie
myobie / poller.ex
Last active April 8, 2021 11:42
GenServer for longpoll requests with backoff in case of errors
defmodule Example.Poller do
use GenServer
@backoff [
50,
100,
150,
250,
400,
650
(defface tree-sitter-hl-face:warning
'((default :inherit font-lock-warning-face))
"Face for parser errors"
:group 'tree-sitter-hl-faces)
(defun hook/tree-sitter-common ()
(unless font-lock-defaults
(setq font-lock-defaults '(nil)))
(setq tree-sitter-hl-use-font-lock-keywords nil)
(tree-sitter-mode +1)
# 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 February 2, 2021 16:55
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.
# 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 September 4, 2020 09:21
Gist about typespecs in Elixir
  • 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 September 1, 2020 07:37
Key concepts to remember from real time phoenix book.
  • 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 July 3, 2023 05:25
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

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

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

@tombigel
tombigel / README.md
Last active May 6, 2024 03:23 — forked from a2ikm/limit.maxfiles.plist
How to Change Open Files Limit on OS X and macOS Sierra (10.8 - 10.12)

How to Change Open Files Limit on OS X and macOS

This text is the section about OS X Yosemite (which also works for macOS Sierra) from https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x

The last time i visited this link it was dead (403), so I cloned it here from the latest snapshot in Archive.org's Wayback Machine https://web.archive.org/web/20170523131633/https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/

Mac OS X

To check the current limits on your Mac OS X system, run: