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
public class Optional<T> { | |
private final boolean isSet; | |
private final T value; | |
public static <T> Optional<T> nothing() { | |
return new Optional<T>(false, null); | |
} | |
public static <T> Optional<T> value(T value) { | |
return new Optional<T>(true, value); |
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
#include <string.h> | |
int main() { char *self = "\"#include <string.h>\nint main() { char *self=%s; char *format = strdup(self+1); format[strlen(format)-2] = 0; print(format, self); return 0;}\""; char *format = strdup(self+1); format[strlen(format)-2] = 0; printf(format, self); return 0;} |
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
#!/usr/bin/env ruby | |
# From "On the Criteria To Be Used in Decomposing Systems into | |
# Modules", David L. Parnas, in CACM 15.12, p. 1053-1058, 1972: | |
# | |
# "The KWIC index system accepts an ordered set of lines, each line is | |
# an ordered set of words, and each word is an ordered set of | |
# characters. Any line may be "circularly shifted" by repeatedly | |
# removing the first word and appending it at the end of the line. The | |
# KWIC index system outputs a listing of all circular shifts of all |
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
#!/usr/bin/env ruby | |
######################################## | |
# numerote.rb | |
# Author: Pierre-Charles David ([email protected]) | |
# Version: 0.1 | |
# Depends on: nothing (except Ruby) | |
# License: General Public License (GPL, see http://www.gnu.org/gpl) | |
# A very simple Ruby script useful to rename a set of files |
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
#!/usr/bin/env ruby | |
print ARGF.readlines.sort_by { rand } |
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
#!/usr/bin/env ruby | |
class String | |
def scrmable | |
return self if not self =~ /\w/m | |
first, *letters = self.split(//) | |
last = letters.pop | |
if last | |
order = Hash.new | |
letters.each do |l| |
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
#!/usr/bin/env ruby | |
######################################## | |
# texml.rb | |
# Author: Pierre-Charles David ([email protected]) | |
# Version: 0.4 | |
# Depends on: xmlparser (available on RAA) | |
# License: General Public License (GPL, see http://www.gnu.org/gpl) | |
# Based of Douglas Lovell's paper: |
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
/** | |
* Illustrates a limitation of the Java type system when using arrays. | |
* The code below compiles without warnings but fails at runtime. | |
*/ | |
public class JavaArraysBreakTypeSafety { | |
public static void main(String[] args) { | |
Object[] t = new String[1]; | |
t[0] = new Integer(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
import java.io.FileReader; | |
import java.io.IOException; | |
import java.io.LineNumberReader; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
/** | |
* Simple example of how to access environment variables in pure Java on Linux in pre-1.5 Java. | |
* Since Java 1.5, System.getenv() can do this in a more portable way. |
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 Module | |
def deprecate(*methodNames) | |
methodNames.each do |methodName| | |
module_eval <<END | |
alias_method :deprecated_#{methodName}, :#{methodName} | |
def #{methodName}(*args, &block) | |
$stderr.puts "Warning: calling deprecated method #{self}.#{methodName}" | |
return deprecated_#{methodName}(*args, &block) | |
end | |
END |
OlderNewer