Skip to content

Instantly share code, notes, and snippets.

View somoza's full-sized avatar
🎯
Focusing

Julián Somoza somoza

🎯
Focusing
  • Argentina
  • 21:46 (UTC -03:00)
View GitHub Profile
@somoza
somoza / phoenix_lieveview_k6.js
Last active August 23, 2024 11:19
K6 script to test Phoenix Liveview entire lifecycle, included socket connection.
import http from "k6/http";
import { sleep, check, fail } from "k6";
import ws from "k6/ws";
export default function () {
const protocol = "https"; // You might want to avoid Cloudflare's DDoS protection or bot mitigation
const host = "domain.com";
const origin = `${protocol}://${host}`;
@somoza
somoza / DateUtils.ex
Created November 26, 2023 00:36
Calculate how many business days are for an option in the market taking in mind T+2 formula
defmodule Module.DateUtils do
@doc """
Functions to help with dates.
"""
@holidays [
# New year
~D[2023-01-01],
# Christmas
~D[2023-12-25]
@somoza
somoza / sieve_atkin.ex
Last active June 12, 2023 14:16
Find prime numbers using Sieve of Atkin on Elixir
defmodule SieveOfAtkin do
def run(limit) do
sieve_range = 1..limit |> Enum.to_list()
sieve = 1..limit |> Enum.into(%{}, fn i -> {i + 1, false} end)
sieve = maybe_add_2_or_3(limit, sieve)
iterate_x(sieve_range, limit, sieve, sieve_range)
|> is_perfect_square(5, limit)
|> Enum.filter(fn {_i, value} -> value end)
@somoza
somoza / base_converter.ex
Created May 19, 2023 16:32
Base number conversion using Elixir
defmodule BaseConverter do
def convert(_digits, _input_base, output_base) when output_base < 2,
do: {:error, "output base must be >= 2"}
def convert(_digits, input_base, _output_base) when input_base < 2,
do: {:error, "input base must be >= 2"}
def convert(digits, input_base, 10) do
maybe_convert_to_base_10(digits, input_base, is_valid_list_of_ints?(digits, input_base))
end
@somoza
somoza / game.ex
Created February 10, 2023 18:43
rock paper scissors
defmodule Game do
@win_combinations [rock: :scissors, paper: :rock, scissors: :paper]
@valid_options [:rock, :paper, :scissors]
def play(player1, player2) do
with {player1, player2} = plays <- validate_params({player1, player2}) do
winner(plays)
else
_ -> "Tiraste fruta"
end
@somoza
somoza / uniqid.ex
Last active August 8, 2022 18:03
unique id generator for Elixir
filename = :crypto.hash(:md5, "#{:os.system_time}") |> Base.encode16
@somoza
somoza / repeated.sql
Created May 16, 2022 14:43
Query to show detailed list of repeated combinations, without using group by
SELECT t1.id, t1.username, t1.client_id
FROM customers AS t1
INNER JOIN(
SELECT username, client_id
FROM customers
GROUP BY username, client_id
HAVING COUNT(username) > 1
)temp ON t1.username = temp.username
order by username, client_id
@somoza
somoza / file.js
Created December 16, 2021 21:01
Prevent double clicking on a link
$('#deleteUrl').one("click", function () {
$(this).click(function () {
return false;
});
});
@somoza
somoza / translations.php
Created August 20, 2021 14:46
PDFTron Native translations for iOS
$labelsDe = [
'%@ Document - %@' => '%1$@ Dokument - %2$@',
'%d of %d' => '%1$d von %2$d',
'%i/%i' => '%1$i/%2$i',
'3D' => '3D',
'Add %@ on Page %d' => '%1$@ auf Seite %2$d hinzufügen',
'Add Author' => 'Author angeben',
'Add Blank Pages' => 'Leere Seiten hinzufügen',
'Add Image as Page' => 'Bild als Seite hinzufügen',
'Add Page' => 'Seite hinzufügen',
@somoza
somoza / translations.php
Created August 20, 2021 14:45
PDFTron Native translations for Android
$labelsEn = [
'tools_qm_note' => 'Note',
'tools_qm_add_note' => 'Add Comment',
'tools_qm_view_note' => 'View Comment',
'tools_qm_appearance' => 'Style',
'tools_qm_textmarkup_type' => 'Type',
'pref_colormode_custom_text_color' => 'Text color',
'tools_qm_color' => 'Color',
'tools_qm_stroke_color' => 'Border color',
'tools_qm_fill_color' => 'Fill color',