Skip to content

Instantly share code, notes, and snippets.

@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 / p702.tokens.cpp.cpp
Last active November 24, 2023 13:36
list of words
// p7e02.words.cpp
// juanfc 2023-11-24
// https://gist.github.com/juanfal/f13931517b6599093996884314d010cc
#include <iostream>
#include <array>
using namespace std;
const int N = 100;
typedef array<string,N> TListWords;
@juanfal
juanfal / t13e18.4inrow.cpp
Created November 23, 2023 10:11
4 in a row
// t13e18.4inrow.cpp
// juanfc 2023-11-09
//
#include <iostream>
#include <array>
using namespace std;
const int COLS = 7;
const int ROWS = 6;
@juanfal
juanfal / t13e11.maxDiag.cpp
Created November 23, 2023 09:54
max diag
// t13e11.maxDiag.cpp
// juanfc 2023-11-23
// Find the greatest sum for the elements of all the pos- sible diagonals of a
// TMat. Take into account that diagonals can go ↘ or ↗. Some diagonals are
// shorter than others.
//
#include <iostream>
#include <iomanip>
@juanfal
juanfal / t11e1.isograms.cpp
Created November 22, 2023 09:35
isograms
// t11e10.isograms.cpp
// juanfc 2023-11-22
// https://gist.github.com/juanfal/1b181c7c25d6af7288678d09a6c5ccae
#include <iostream>
#include <array>
using namespace std;
typedef array<int,256> TCharFreq;