Skip to content

Instantly share code, notes, and snippets.

View luizpvas's full-sized avatar

Luiz Paulo de Vasconcellos luizpvas

View GitHub Profile
defmodule MyRouter do
use Plug.Router
# Starts the server
def start do
Plug.Adapters.Cowboy.http MyRouter, []
end
plug :my_handle # custom plug
plug :match
@luizpvas
luizpvas / WikiConsolidator.py
Created August 22, 2017 22:17
Consolidate the output from WikiExtractor.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ===========================================
#
# WikiConsolidator reads a directory with .bz2 files generated by WikiExtractor.
# The files are compiled into one .txt file, where each line is a pre-processed
# sentence. The following transformations and filters are applied in the text:
#
# * Commas, dots, quotes and parathensis are removed. Question and exclamation
# marks are kept, but with spaces between then and words. For example:
@luizpvas
luizpvas / hipsters_scrapper.js
Created October 12, 2018 20:25
Extração de comentários do Podcast Hipsters.tech
const puppeteer = require('puppeteer');
const fs = require('fs');
// Ids of the episodes. Each ID must be passed to the URL in the format of
// hipsters.tech?page_id=<page_id>.
//
// I grabbed these ids calling `Array.from(document.querySelectorAll('#page_id option')).map(option => option.value)`
// in any episode page. The episodes are listed in a select input, which was really handy.
let pageIds = ["1940","1932","1915","1923","1910","1901","1893","1884","1877","1868","1864","1854","1847","1823","1800","1791","1785","1763","1757","1749","1740","1736","1729","1718","1708","1697","1689","1684","1676","1661","1646","1642","1635","1623","1614","1591","1586","1571","1548","1526","1508","1475","1468","1445","1416","1404","1391","1371","1355","1339","1326","1298","1281","1262","1245","1067","1040","1141","1129","1115","1005","1058","1045","1030","1015","1007","984","989","963","948","939","930","923","917","887","878","871","866","859","835","827","816","806","793","778","670","680","689","718","685","683","667","
module Colorpicker exposing (main)
-- The Browser module has the definition we need to run an Elm application in the
-- Elm architecture.
-- Html is the module that defines the functions `div`, `span`, `button`, etc.
-- Html.Attributes exposes functions for element attributes such as `class` and `id`.
-- Html.Events exposes functions for binding elements such as `onClick` and `onInput`.
import Browser
import Html exposing (..)
defmodule AppWeb.Live.Subscription do
use Phoenix.LiveView
alias AppWeb.Router.Helpers, as: Routes
def render(assigns) do
~L"""
<form class="flex" phx-submit="submit">
<div class="w-1/2 mr-8">
<%= if @billing_period == :monthly do %>
<button class="border-2 text-sm py-1 px-2 rounded text-green-500 border-green-500">Monthly</button>
# CONTROLER
class MyApp::InvoicesController
def index
input = { interval: params[:interval] }
MyApp::GetInvoices.call(input) do |on|
on.success do |result|
# ...
end
@luizpvas
luizpvas / _item.html.erb
Created January 17, 2024 00:45
Anycable reliable stream (demo)
<div><%= item %></div>
@luizpvas
luizpvas / gist:db6713f08d5ba0bf295d0015f41be94d
Last active January 17, 2024 01:05
anycable debug logs
incoming data
Object { type: "ping", message: 1705453463 }
application.agent_app-3f3c6c5a6db9c83f5f356179e605a23f20efe7c1.js:6524:23
acquiring subscribe lock
Object { identifier: '{"channel":"Turbo::StreamsChannel","signed_stream_name":"Iml0ZW1zLWIi--c7c70aed589783926494bd92e98984a799065a27f07c59a73a195c03fca19066"}' }
application.agent_app-3f3c6c5a6db9c83f5f356179e605a23f20efe7c1.js:6524:23
unsubscribe lock has been acquired
Object { identifier: '{"channel":"Turbo::StreamsChannel","signed_stream_name":"Iml0ZW1zLWEi--051ad5245fcd7cfe8583515ebda421eb423781f99bea91f811cc9a787d89d39d"}' }
application.agent_app-3f3c6c5a6db9c83f5f356179e605a23f20efe7c1.js:6524:23
unsubscribing...
@luizpvas
luizpvas / micro_case.rb
Last active February 2, 2024 19:18
rails instrumentation
if Rails.env.development?
::ActiveSupport::Notifications.subscribe 'µ-case' do |*args|
result = args.extract_options![:result]
description = result.use_case.class.name
Rack::MiniProfiler.step("µ-case: #{description}") do
Rails.logger.warn "µ-case called: #{description}"
end
end
# Versys
### Public endpoints
```bash
# request
curl -XPOST 'https://versys-cb8d3b16a9ae.herokuapp.com/api/v1/auth/registration' -H 'Content-Type: application/json' \
-d '{"full_name": "Luiz Vasconcellos", "email_address": "luizpvasc@gmail.com", "username": "luizpvas", "password": "mystrongpassword", "terms_of_use": true}'
# response