Skip to content

Instantly share code, notes, and snippets.

View jonalmeida's full-sized avatar
🦊
making browsers..

Jonathan Almeida jonalmeida

🦊
making browsers..
View GitHub Profile
@jonalmeida
jonalmeida / fenix_feature_directory.txt
Created December 16, 2020 16:21
Output of `exa -Td --ignore-glob="*.kt"` as of 15/12/20
.
├── addons
├── browser
│ ├── browsingmode
│ └── readermode
├── collections
├── components
│ ├── history
│ ├── metrics
│ ├── search
@jonalmeida
jonalmeida / presto_fare_total.py
Created October 2, 2018 17:13
Get the total spent from an exported CSV on Presto (prestocard.ca)
#!/usr/bin/env python3
import csv, sys, re
from functools import reduce
"""
From StackOverflow: https://stackoverflow.com/a/32486472
Strips whitespace off from the headers of CSV field names.
"""
@jonalmeida
jonalmeida / README.md
Created April 24, 2017 06:36
Scaling the frequency server

Scaling the frequency server

In my solution I used a simple round robin implementation to choose between the two servers. I separated the balancer module from the frequency to make the implementation cleaner. I've also moved allocated/0 and deallocated/1 to this module since they are the interfaces.

Scaling up

Suppose that the frequency server needs to serve more frequencies. It would be possible to do this just by having a longer list of frequencies available, but it is likely that this scaling is required not only because more frequencies are needed but also because there are more requests to allocate and de-allocate them.

Sharding the handling of frequencies

@jonalmeida
jonalmeida / README.md
Last active April 20, 2017 06:05
Supervision in the frequency server

Supervision in the frequency server

To give a design understanding of my code. There is a server, supervisor and client that all have their own loops. The server can be started without the supervisor with frequency:start/0. If the server fails, it will not be restarted. To start the server with a supervisor, you can do so with frequency:sup_start/0. To simulate clients, use frequency:sim_clients(N). You can simulate N number of clients running. The function returns the Pids of the spawned processes.

Things to note:

  • Because of the timeouts, you'll notice that if you spawn 3 process, you won't always use 3 frequencies. Some times a process will be sleeping so only 2 or 1 process may be running. You can alter the sleep calls accordingly to change this.
  • I register the atom io with the main pid (i.e. the shell) so that logging can be sent back to it with ease.
  • I've added a lot of logging during each attempt/failure so it might be too verbose for you. Comment some out accordingly.

@jonalmeida
jonalmeida / server.erl
Last active April 8, 2017 20:48
Concurrent frequency and ping server
-module(server).
-export([ping/1, init/0]).
% Usage in shell:
%register(server, spawn(server, init, [])).
%server ! {request, self(), allocate}.
%server ! {request, self(), {deallocate, Freq}}.
%register(client, spawn(server, init, [])).
%server ! {ping, client}. % WARNING! This ping-pong server will never end!
@jonalmeida
jonalmeida / README.md
Last active December 20, 2016 01:35
Simple test web server

Simple test web server

Requirements

  • NodeJS
    • Preferably the latest or (if you're on a Mac) with brew install nodejs.

Instructions

  1. Put the package.json and app.js files in a folder
  2. Run npm install
  3. Edit the app.get and app.post examples to fit your needs.
src/lib.rs:27:28: 27:32 error: `name` does not live long enough
src/lib.rs:27 let name_str = name.as_str();
^~~~
src/lib.rs:24:37: 36:6 note: reference must be valid for the lifetime 'a as defined on the block at 24:36...
src/lib.rs:24 where T: Into<Cow<'a, str>> {
src/lib.rs:25 let uuid = Uuid::new_v4();
src/lib.rs:26 let name = uuid.to_string();
src/lib.rs:27 let name_str = name.as_str();
src/lib.rs:28 let mut clocks = HashMap::new();
src/lib.rs:29 clocks.insert(name_str, 0);
src/lib.rs:25:25: 25:51 error: borrowed value does not live long enough
src/lib.rs:25 let name = Uuid::new_v4().to_string().as_str();
^~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:24:37: 34:6 note: reference must be valid for the lifetime 'a as defined on the block at 24:36...
src/lib.rs:24 where T: Into<Cow<'a, str>> {
src/lib.rs:25 let name = Uuid::new_v4().to_string().as_str();
src/lib.rs:26 let mut clocks = HashMap::new();
src/lib.rs:27 clocks.insert(name, 0);
src/lib.rs:28
src/lib.rs:29 Client {
# Converting markdown to pdf using pandoc; a quick function wrapper
export PATH=/usr/texbin:$PATH
md2pdf() {
pandoc $1 -o `basename $1 .md`.pdf
}
@jonalmeida
jonalmeida / README.md
Created July 24, 2015 18:11
Notifies you when your try build is complete.

Why

Instead of checking when your try build is complete, this short python script checks try every 5 mins (you can change the interval if you like) using the treeherder API to see if your try push is complete. Gives you a simple notification in your Notification Center (on Mac OS).

How To Use

  • chmod +x try_to_notify
  • (Optional) Move to your /usr/local/bin and remove .py extension
  • try_to_notify [sha_of_the_try_push]

Examples