This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ping-host-list | |
# | |
# ping a list of hosts | |
# | |
$Host_List_Path = ".\hostlist.txt" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# How many days until Christmas? | |
# | |
function DaysToXmas() | |
{ | |
$now = Get-Date | |
$Xmas = Get-Date -Day 25 -Month 12 | |
if ($now -gt $Xmas) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc x {} { set y "x" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
OlderNewer