Skip to content

Instantly share code, notes, and snippets.

View realeroberto's full-sized avatar
💭
Trust your journey.

Roberto Reale realeroberto

💭
Trust your journey.
View GitHub Profile
@realeroberto
realeroberto / typewriter.py
Last active August 29, 2015 14:15
Given text and a desired line length, wrap the text as a typewriter would...
# Given text and a desired line length, wrap the text as a typewriter would.
# An exercise from MITx: 6.00.1x Introduction to Computer Science and Programming Using Python.
def typewriter(text, lineLength):
"""
Given text and a desired line length, wrap the text as a typewriter would.
Insert a newline character ("\n") after each word that reaches or exceeds
the desired line length.
text: a string containing the text to wrap.
@realeroberto
realeroberto / iterative_prime_generator.py
Last active June 6, 2021 18:29
A simple Python iterator that returns the sequence of prime numbers on successive calls to its next() method...
class PrimeGenerator:
def __init__(self):
self.primes = []
self.current_prime = 1
def __iter__(self):
return self
def __next__(self) -> int:
candidate = self.current_prime + 1
@realeroberto
realeroberto / vcenter_get_host_uuids.ps1
Created August 19, 2015 15:28
Get UUIDs for every host known to a vSphere vCenter Server
# after proper connection...
Get-VMHost | Select-Object Name, @{Name="UUID"; Expression={($_ | Get-View).hardware.systeminfo.uuid}}
@realeroberto
realeroberto / factorial.scm
Last active February 6, 2016 14:21
Tail-recursive factorial in Scheme.
;
; Tail-recursive factorial in Scheme.
;
(define (factorial n)
(if (= n 1)
1
(* n (factorial(- n 1)))))
@realeroberto
realeroberto / insertion-sort.c
Created February 6, 2016 14:28
A naive implementation of Insertion Sort in C.
/*
* a naive implementation of Insertion Sort in C.
*/
void
insertion_sort(int *array, int array_len)
{
int i;
for (i = 1; i < array_len; i++) {
@realeroberto
realeroberto / factorial.d
Last active February 6, 2016 14:32
Tail-recursive factorial() in D.
import std.stdio;
ulong
factorial(int n)
{
if(n < 2)
return 1;
else
return n * factorial(n - 1);
}
@realeroberto
realeroberto / factorial.sml
Created February 6, 2016 14:57
My first attempt at "coding" in Standard ML.
(* factorial *)
(* my first Standard ML ``program'' *)
(* see the excellent tutorial at *)
(* http://www.soc.napier.ac.uk/course-notes/sml/manual.html *)
fun factorial(1) = 1
| factorial(n) = n * factorial(n-1);
@realeroberto
realeroberto / delete-tranches.sql
Last active September 15, 2018 22:12
PL/SQL trick: delete rows in tranches.
--
-- delete rows in tranches
--
-- inspired by the discussion at http://kr.forums.oracle.com/forums/thread.jspa?threadID=365130
--
set serveroutput on
DECLARE
ln_DelSize NUMBER := 500;
@realeroberto
realeroberto / GrayCode.ps1
Created November 3, 2016 14:03
Convert an integer to its Gray-code representation.
#
# convert an integer to its Gray-code representation
#
Add-Type -TypeDefinition @'
public class shift {
public static int lshift(int x, int count) { return x << count; }
public static int rshift(int x, int count) { return x >> count; }
}
'@
@realeroberto
realeroberto / e-power-series-gui.tcl
Created November 11, 2016 10:01
Approximate the value of e using the power series expansion (with GUI).
#
# approximate the value of e using the power series expansion (with GUI)
#
# see http://www.tkdocs.com/tutorial/firstexample.html
#
package require Tk