Skip to content

Instantly share code, notes, and snippets.

View ostinelli's full-sized avatar

Roberto Ostinelli ostinelli

View GitHub Profile
@ostinelli
ostinelli / 1_searchbar_live.ex
Created May 2, 2024 12:40 — forked from caspg/1_searchbar_live.ex
Example of real-time search bar implementation in Phoenix LiveView and Tailwind. Working example on https://travelermap.net/parks/usa
defmodule TravelerWeb.SearchbarLive do
use TravelerWeb, :live_view
alias Phoenix.LiveView.JS
alias Traveler.Places
def mount(_params, _session, socket) do
socket = assign(socket, places: [])
{:ok, socket, layout: false}
end
@ostinelli
ostinelli / rsa_openssl_for_python.md
Last active April 16, 2024 07:05
RSA Private / Public key pair with openssl & Python

RSA Private / Pubic key pair

To generate a private / public RSA key pair, you can either use openssl, like so:

$ openssl genrsa -out private.pem 4096  
$ openssl rsa -in private.pem -outform PEM -pubout -out public.pem  

Or, you can use the following python script:

@ostinelli
ostinelli / ecdsa_example.rb
Last active April 14, 2024 17:32
ECDSA usage from Ruby.
require 'openssl'
require 'base64'
# ===== \/ sign =====
# generate keys
key = OpenSSL::PKey::EC.new("secp256k1")
key.generate_key
public_key = key.public_key
public_key_hex = public_key.to_bn.to_s(16).downcase # public key in hex format
@ostinelli
ostinelli / block.ex
Created February 28, 2023 10:41
Calling a block passed in a macro in Elixir
defmodule Foo do
defmacro foo(do: block) do
quote do
res = unquote(block)
IO.inspect(res)
end
end
end
defmodule Use do
@ostinelli
ostinelli / jenkins_ci_on_osx.md
Last active February 28, 2023 02:38
Setup Jenkins CI on OSX.

Jenkins CI on OSX

Instructions on how to setup a secured Jenkins CI on a Mac.

Download & Install dependencies

All of these operations are done with your admin user.

Developer tools

Install the command line developer tools.

@ostinelli
ostinelli / jenkins_ci_on_ubuntu.md
Last active February 14, 2023 07:12
Setup Jenkins CI on Ubuntu.

Jenkins CI

Instructions on how to setup a secured Jenkins CI.

Install Jenkins

$ wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
$ sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list$ .d/jenkins.list'
$ sudo apt-get update
$ sudo apt-get install jenkins
@ostinelli
ostinelli / logentries_manual_setup.md
Last active August 11, 2022 21:37
How to use a single Logentries account on Heroku.

If you have multiple applications on Heroku and would like to use a single Logentries account for all of them, this is how you do it. Basically, do not use add-ons, and send all drains to your account.

  • In your Logentries account, click on Add Log
  • Select Manual
  • In the form that appears, input the following:
    • Log Name: access.log
    • Select Set: new set named myapp-{environment}, for instance myapp-staging (at least, this is how I like to name my entries)
    • Select the Plain TCP, UDP - logs are sent via syslog option
  • Click on Create Log Token
@ostinelli
ostinelli / worker.ex
Last active August 11, 2022 17:43
Elixir DynamicSupervisor with registered worker ids (local registry, use :syn for global workers instead)
defmodule MyApp.Worker do
use GenServer
# api
@spec start_link(worker_id :: String.t()) :: GenServer.on_start()
def start_link(worker_id) do
GenServer.start_link(__MODULE__, [worker_id], name: via_tuple(worker_id))
end
@ostinelli
ostinelli / dvvset_test.erl
Last active December 17, 2021 12:12
Dotted Version Vector Sets example on conflict detection
-module(dvvset_test).
-export([main/0]).
%% NOTE: we always generate a new client ID to enforce consistency.
main() ->
%% client 1 write
Dot0 = dvvset:update(dvvset:new("value-0"), generate_id()),
%% server
@ostinelli
ostinelli / kv_bench.erl
Last active October 23, 2021 11:20
Erlang take values from KV stores (dict vs orddict vs maps vs gb_sets vs ets set vs ets bag benchmark)
-module(kv_bench).
-compile([export_all]).
main(Count) ->
Values = lists:foldl(fun(C, Acc) ->
[{C, {v, C}} | Acc]
end, [], lists:seq(1, Count)),
{TimeDict, ResultDict} = timer:tc(?MODULE, get_last_dict, [Count, Values]),