Skip to content

Instantly share code, notes, and snippets.

View ulisesantana's full-sized avatar
😍
In love with TypeScript

Ulises Santana ulisesantana

😍
In love with TypeScript
View GitHub Profile
@ulisesantana
ulisesantana / os-report.mjs
Last active March 4, 2022 08:49
A simple OS Report function
export function osReport(os) {
const cpus = os.cpus()
const totalMemory = os.totalmem()
const freeMemory = os.freemem()
const usedMemory = totalMemory - freeMemory
return `
Arch: ${os.arch}
CPUS: ${cpus.length} (${cpus[0].model} ${cpus[0].speed})
Memory: ${fromBytesToGigabytes(usedMemory)}/${fromBytesToGigabytes(totalMemory)}
Platform: ${os.platform}
@ulisesantana
ulisesantana / generate-huge-json.mjs
Last active April 10, 2024 19:09
Script for generating a JSON file with 100 million records. The output file size is 8,1 GB.
import { Readable, pipeline } from 'stream'
import fs from 'fs'
import path from 'path'
import { EOL } from 'os'
function createTransaction () {
return {
date: new Date(Math.random() * 100_000_000_000),
type: Math.random() > 0.5 ? 'INCOME' : 'OUTCOME',
amount: +(Math.random() * 100).toFixed(2)
@ulisesantana
ulisesantana / algebraicTypes.rs
Created November 16, 2021 23:46
Ejemplo de tipos algebraicos en Rust
pub mod flight_discount {
pub trait Discount {
fn percentage(self: Self) -> u8;
}
#[allow(dead_code)]
pub enum SpanishSubsidy {
LargeFamily,
ResidentOfIslandsOrCeuta,
SpecialResidentLargeFamily,
@ulisesantana
ulisesantana / algebraicTypes.ts
Created October 19, 2021 16:26
Ejemplo de tipos algebraicos en TypeScript
enum DiscountKind {
NoDiscount,
Special,
Resident,
Family,
Business
}
interface Discount {
kind: DiscountKind;
@ulisesantana
ulisesantana / .zshrc
Last active January 10, 2023 10:30
Raspberry Pi init script
# Prevent from using the custom alias on 3rd party scripts. Must be at the top of the file
[ -z "$PS1" ] && return
# alias
alias blog='cd ~/projects/blog'
alias blog-posts='cd ~/projects/blog/content/blog'
alias .zshrc='nvim ~/.zshrc'
alias gitlog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias wifi='nmcli device show wlan0'
function cd {
@ulisesantana
ulisesantana / init.vim
Created July 12, 2021 16:46
Neovim plugins config
" Based on this post https://stsewd.dev/es/posts/neovim-plugins/
call plug#begin('~/.local/share/nvim/plugged')
Plug 'yashguptaz/calvera-dark.nvim'
Plug 'scrooloose/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes' " Temas para airline
@ulisesantana
ulisesantana / new-post.sh
Created May 2, 2021 09:48
Generate a file with current day as file name based on template. Will create a folder based on current month and save the file inside.
#!/usr/bin/env bash
check() {
test "$@" && echo true || echo false
}
show_help() {
echo -e "Generate a file with current day as file name based on template. Will create a folder based on current month and save the file inside.\n"
echo -e "Usage: new-post.sh template_path output_parent_directory.\n"
echo -e "Example: ./new-post.sh ./template.md ./posts
@ulisesantana
ulisesantana / fizzBuzz.test.ts
Created May 15, 2020 22:04
Fizz Buzz TDD with Deno
import fizzBuzz, { FIZZ, BUZZ, FIZZ_BUZZ } from "./fizzBuzz.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
Deno.test(
"FizzBuzz should return the same number given if is not divisible by 3 or 5",
() => {
assertEquals(fizzBuzz(1), 1);
},
);
Deno.test(
@ulisesantana
ulisesantana / git_shortcuts.sh
Created January 21, 2020 21:35
Shortcuts for git
alias gitstats='git-stats'
alias gits='git status -s'
alias gita='git add -A && git status -s'
alias gitcom='git commit -am'
alias gitacom='git add -A && git commit -am'
alias gitc='git checkout'
alias gitcm='git checkout master'
alias gitcd='git checkout development'
alias gitcgh='git checkout gh-pages'
alias gitb='git branch'
@ulisesantana
ulisesantana / generateMock.script.js
Created December 18, 2019 16:50
Mock generator
const { address, company, random } = require('faker');
const fs = require('fs');
const path = require('path');
fs.writeFile(
path.resolve('companies.mock.json'),
JSON.stringify(
[...new Array(60)].map(() => ({
id: random.number(),
name: company.companyName(),