Skip to content

Instantly share code, notes, and snippets.

// t03e06.dogage.cpp
// juanfc 2021-10-17
// Write a program to calculate a dog's age in dog's years.
// For the first two years, a dog year is equal to 10.5 human years. After that,
// each dog year equals 4 human years. For example:
// \begin{code}
// Input a dog's age in human years: 15
// The dog's age in dog's years is 73
// https://gist.github.com/6fbc2f4c93c4855ae90bf919f135e603
@juanfal
juanfal / dmgFromFolders.rb
Last active March 16, 2024 14:38
Create .dmg disk image from folder(s) in a smart way
#!/usr/bin/env ruby -wU
# juanfc 2024-03-16
# https://gist.github.com/juanfal/39206b7d47a1eacac35cbd1b98f6f5d3
if ARGV.length < 1 or (ARGV.length == 1 and ARGV[0] == '-h') then
puts "Usage:
#$0 [destdmg] sourceFolder [sourceFolders..]
"
exit 0
end
@juanfal
juanfal / myip
Created January 11, 2024 08:18
local and external IP bash resolver
#!/bin/sh
# myip
# juanfc 2024-01-11
# wget http://ipinfo.io/ip -qO -
# ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null
# dig +short myip.opendns.com @208.67.222.222
# dig +short myip.opendns.com @resolver1.opendns.com
# ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null
@juanfal
juanfal / gist:9df45a63431541f156659ad06dcf2922
Created January 8, 2024 17:59
m biggest numbers and their positions
// x3.mbiggest.cpp
// juanfc 2024-01-08
// Without open array
//
#include <iostream>
#include <array>
using namespace std;
const int MAXDIFNUMS = 50;
@juanfal
juanfal / x2.maxdistrepwords.cpp
Created January 8, 2024 17:52
distance between repeated words
// x2.maxdistrepwords.cpp
// juanfc 2024-01-08
//
// The \textbf{distance between two words} in a text is the number of words in
// between them. Build an algorithm that reads from keyboard a sequence of words
// and then print on the screen the maximum distance between repeated words.
// Words that are no repeated will not appear in the output.
#include <iostream>
@juanfal
juanfal / x1.words.cpp
Created January 8, 2024 17:30
unique words first position entered
// x1.words.cpp
// juanfc 2024-01-08
//
#include <iostream>
#include <array>
using namespace std;
const int MAX_DIFF_WORDS = 1000;
const int MAX_REP = 1000;
@juanfal
juanfal / t13e18.GameOfLife.cpp
Last active December 12, 2023 10:30
Game of Life (depends only on usleep and standard VT100 terminal escape seq to clean the terminal)
// t13e18.GameOfLife.cpp
// juanfc 2023-12-11
// https://gist.github.com/juanfal/14e0ffcb4439a5544a9c08768b6b3a99
//
// Three rules:
// INITIAL STATE -> FINAL STATE
// dead with 3 -> alive
// alive with 2 or 3 -> alive
// else -> dead
//
@juanfal
juanfal / t12e07.polynomials.cpp
Last active December 4, 2023 09:23
polynomials with open arrays
// t12e07.polynomials.cpp
// juanfc 2023-11-23
// https://gist.github.com/baf068a06eafb1ecba8a584fe375b780
// Elements of the polynomials are kept ordered
// from highest to lowest degrees
//
#include <array>
#include <iostream>
using namespace std;
@juanfal
juanfal / t13e03.identityMat.cpp
Last active November 28, 2023 07:21
building an identity matrix
// t13e03.identityMat.cpp
// juanfc 2023-11-23
//
#include <iostream>
#include <array>
using namespace std;
const int N = 3;
typedef array<array<int, N>,N> TSqMat;
@juanfal
juanfal / sieveOfRepeated.cpp
Last active November 27, 2023 16:43
Sieve a list picking up the elements repeated a certain number of times
// sieveOfRepeated.cpp
// juanfc 2023-11-27
// https://gist.github.com/079916adc1420f95017328d1f04797e7
#include <iostream>
#include <array>
using namespace std;
const int MAX = 100;
struct TOpenAr {