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 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. |
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
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 |
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
# after proper connection... | |
Get-VMHost | Select-Object Name, @{Name="UUID"; Expression={($_ | Get-View).hardware.systeminfo.uuid}} |
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
; | |
; Tail-recursive factorial in Scheme. | |
; | |
(define (factorial n) | |
(if (= n 1) | |
1 | |
(* n (factorial(- n 1))))) |
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
/* | |
* 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++) { |
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
import std.stdio; | |
ulong | |
factorial(int n) | |
{ | |
if(n < 2) | |
return 1; | |
else | |
return n * factorial(n - 1); | |
} |
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
(* 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); |
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
-- | |
-- 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; |
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
# | |
# 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; } | |
} | |
'@ |
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
# | |
# approximate the value of e using the power series expansion (with GUI) | |
# | |
# see http://www.tkdocs.com/tutorial/firstexample.html | |
# | |
package require Tk | |