Skip to content

Instantly share code, notes, and snippets.

View arleypadua's full-sized avatar
🤓
Learning

Arley Pádua arleypadua

🤓
Learning
View GitHub Profile
@arleypadua
arleypadua / download_and_unzip.sh
Last active March 27, 2024 19:40
Batocera useful bash scripts
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <system> <url>"
exit 1
fi
# Assign command line arguments to variables
url="$2"
@arleypadua
arleypadua / givenWhenThen.kt
Last active November 24, 2023 14:41
Given/When/Then experiment
data class GivenContext<T>(val given: T)
data class WhenContext<G, W>(val given: G, val outcome: W)
private fun <T> given(block: () -> T): GivenContext<T> = GivenContext(block())
private fun <T, W> GivenContext<T>.whenn(block: GivenContext<T>.() -> W): WhenContext<T, W> =
WhenContext(given, block())
private fun <T, W> WhenContext<T, W>.then(block: WhenContext<T, W>.(outcome: W) -> Unit) {
block(this.outcome)
}
@arleypadua
arleypadua / docker-compose.yml
Created November 10, 2023 10:57
Graph notebook + Gremlin Server docker compose
version: '3.8'
services:
graph-notebook:
image: public.ecr.aws/neptune/graph-notebook:3.9.0
ports:
- "8889:8889"
- "8888:8888"
environment:
- GRAPH_NOTEBOOK_HOST=gremlin-server
- GRAPH_NOTEBOOK_SSL=False
@arleypadua
arleypadua / 00-split-pdf.js
Created July 22, 2023 13:25
Split PDF into individual ones by index
import { PDFDocument } from 'pdf-lib'
import { promises as fsp } from "fs"
function readPdf(path) {
return fsp.readFile(path)
}
// only works on a sorted array by bage
function findSongFinalPage(array, currentIndex) {
const currentSong = array[currentIndex]
@arleypadua
arleypadua / prullenbakvaccin-nl-notifications.js
Created May 25, 2021 21:56
Copy and paste this onto the console and this will notify you of locations available for vaccines in the Netherlands
// made to be used at: https://www.prullenbakvaccin.nl/
let jobResources = {
streetAndNumberRegex: /([A-Z])\w+ ([0-9])\w+,/,
cityAndZipCodeRegex: /\d{4}([A-Z]){2} ([A-Z])\w+/
}
async function notify(text) {
if(Notification.permission === "granted") {
let notification = new Notification('New vaccination location available', {
@arleypadua
arleypadua / sum-my-org-contributions.js
Created November 17, 2020 11:15
This will sum all your GitHub contributions in an organization
// 1 - access https://github.com/settings/tokens
// 2 - create a personal access token, giving it permissions: repo, read:org, read:user
// 3 - paste the token in the constant below
// 4 - put the user name that you want to find
// 5 - put the organization in which the script will look-up for commits/additions/deletions
// 6 - script is compatible with Chrome, as it uses the fetch API
let token = '[PASTE-TOKEN-HERE]'
let username = '[PUT-YOUR-USERNAMEHERE]'
let organization = '[PUT-YOUR-ORGANAZATION-ID-HERE]'
@arleypadua
arleypadua / Order.cs
Last active August 4, 2023 12:52
Rich Domain Model
public class Order
{
private Order() { }
public string OrderId { get; private set; }
public string CustomerId { get; private set; }
public decimal Discount { get; private set; }
public bool Paid { get; private set; }
public DateTime? PaymentTime { get; private set; }
public DateTime CreationTime { get; private set; }
@arleypadua
arleypadua / encapsulated-list.cs
Created September 1, 2018 11:46
encapsulating-list
private List<OrderItem> _items; // The original source is private and can only be modified by this class.
public IEnumerable<OrderItem> Items => _items.AsReadOnly(); // Exposes a readonly copy of order items
@arleypadua
arleypadua / order-item-domain-model.cs
Last active August 22, 2018 04:10
order-item-domain-model
public class OrderItem
{
private OrderItem() { }
public static OrderItem New(string productId, int quantity, decimal price, decimal discount = 0)
{
if (string.IsNullOrWhiteSpace(productId)) throw new ArgumentNullException(nameof(productId));
if (quantity <= 0) throw new ArgumentOutOfRangeException(nameof(quantity));
if (price <= 0) throw new ArgumentOutOfRangeException(nameof(price));
if (discount < 0) throw new ArgumentOutOfRangeException(nameof(discount));
@arleypadua
arleypadua / anemic-domain-model-encapsulated-constructor.cs
Last active August 21, 2018 17:54
anemic-domain-model-encapsulated-constructor
public static Order New(string orderId, string customerId, DateTime? creationTime = null)
{
if (string.IsNullOrWhiteSpace(orderId)) throw new ArgumentNullException(nameof(orderId));
if (string.IsNullOrWhiteSpace(customerId)) throw new ArgumentNullException(nameof(customerId));
return new Order
{
OrderId = orderId,
CustomerId = customerId,
CreationTime = creationTime ?? DateTime.UtcNow,