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 / cidr_prefix_to_netmask.php
Created July 11, 2014 15:42
Convert a Classless Inter-Domain Routing prefix to a plain old network mask.
<?php
/*
* Convert a Classless Inter-Domain Routing prefix to a plain old network mask.
*
* E.g.: 24 => 255.255.255.0
*/
function cidr_prefix_to_netmask($prefix)
{
@realeroberto
realeroberto / ps_ping_host_list.ps1
Created August 11, 2014 13:34
Ping a list of hosts, in PowerShell.
#
# ping-host-list
#
# ping a list of hosts
#
$Host_List_Path = ".\hostlist.txt"
@realeroberto
realeroberto / rename_files_iso8601.ps1
Created November 4, 2014 11:55
Rename a bunch of files with embedded dates as ISO 8601 dates.
#
# rename a bunch of files as follows
#
# DDMONYYYY_NAME.EXT ==> YYYY-MM-DD_NAME.EXT
#
# i.e. it changes the date to ISO 8601 form
#
# for each file in the local path
@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
@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 / 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 / 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 / self_evaluating_proc.tcl
Created February 17, 2015 08:40
A «self-evaluating» proc in Tcl.
proc x {} { set y "x" }
@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 / 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')