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 / 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 / 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 / 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 / x_ian.py
Created February 17, 2015 22:04
X-ian, in Python.
# Given a string x, returns True iff all the letters in x
# are contained in word in the same order as they appear in x.
# An exercise from MITx: 6.00.1x Introduction to Computer Science and Programming Using Python.
def x_ian(x, word):
"""
Given a string x, returns True iff all the letters in x are
contained in word in the same order as they appear in x.
>>> x_ian('eric', 'meritocracy')
@realeroberto
realeroberto / reverse_string_recursively.py
Last active August 29, 2015 14:15
Recursive String Reversal in Python.
# Recursively returns a reversed copy of the given string.
# An exercise from MITx: 6.00.1x Introduction to Computer Science and Programming Using Python.
def reverseString(aStr):
"""
Given a string, recursively returns a reversed copy of the string.
For example, if the string is 'abc', the function returns 'cba'.
The only string operations you are allowed to use are indexing,
slicing, and concatenation.
@realeroberto
realeroberto / self_evaluating_proc.tcl
Created February 17, 2015 08:40
A «self-evaluating» proc in Tcl.
proc x {} { set y "x" }
@realeroberto
realeroberto / trabb_pardo_knuth.ps1
Last active August 29, 2015 14:15
The Trabb Pardo–Knuth algorithm.
#
# Trabb Pardo–Knuth algorithm
#
# see http://rosettacode.org/wiki/Trabb_Pardo%E2%80%93Knuth_algorithm
#
function TPK_function($x)
{
return [math]::pow([math]::abs($x), .5) + 5 * [math]::pow($x, 3)
@realeroberto
realeroberto / days_to_christmas.ps1
Created February 17, 2015 07:23
How many days until Christmas?
#
# How many days until Christmas?
#
function DaysToXmas()
{
$now = Get-Date
$Xmas = Get-Date -Day 25 -Month 12
if ($now -gt $Xmas) {
@realeroberto
realeroberto / generic_equality_mixin.py
Last active August 29, 2015 14:15
A generic equality mixin in Python.
# Generic equality mixin
# http://stackoverflow.com/questions/390250/
class EqualityMixin(object):
def __eq__(self, other):
if type(other) is type(self):
return self.getX() == other.getX() and self.getY() == other.getY()
else:
return False
def __ne__(self, other):
@realeroberto
realeroberto / rename_files_iso8601_with_progressive_id.ps1
Created November 26, 2014 11:42
Add a progressive identifier to file names with embedded ISO 8601 dates.
#
# rename a bunch of files as follows
#
# YYYY-MM-DD_NAME.EXT ==> YYYY-MM-DD_nnnn_NAME.EXT
#
# where nnnn is a progressive identifier
#
# initialize the progressive identifier