This file contains hidden or 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 IPLocator | |
| attr_accessor :ranges | |
| def initialize(filename) | |
| self.ranges = [] | |
| File.open(filename).each do |line| | |
| if not line.start_with? '#' | |
| start, stop, country = line.split | |
| self.ranges << IPRange.new(start.to_i, stop.to_i, country) |
This file contains hidden or 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
| %s/<!--\_.\{-}-->//g |
This file contains hidden or 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.util.*; | |
| import java.io.*; | |
| public class Dictionary { | |
| private List<String> words; | |
| public Dictionary(List<String> list) { | |
| this.words = list; | |
| } | |
This file contains hidden or 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
| /** | |
| * Calculates average over the last X data points. | |
| * | |
| * All operations are constant time (O(1)). | |
| * | |
| * Note the possibility of overflow, if the sum | |
| * of the last X data points exceeds Float.MAX_VALUE. | |
| */ | |
| class MovingAverage { | |
| private final int maxSize |
This file contains hidden or 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
| players = ['sergei','birger','vincent','geir','harald','alex'] | |
| players.shuffle.each_slice(2) do |a,b| | |
| puts "#{a} - #{b}" | |
| end |
This file contains hidden or 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
| awk -F'\t' '{ if(a[$1]) a[$1]=a[$1]","$2; else a[$1]=$2;} END {for (i in a) print i, a[i];}' OFS='\t' clickthroughs.tsv | sort > clickthroughs2.tsv |
This file contains hidden or 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 CumulativeMovingAverage { | |
| int n = 0; | |
| double average = 0.0; | |
| public double add(double x) { | |
| return average += (x - average) / ++n; | |
| } | |
| } |
This file contains hidden or 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 TopList<E extends Comparable> { | |
| @Delegate | |
| private List items | |
| private int maxSize | |
| private Comparator<E> comparator = new ReverseComparator() | |
| TopList(int maxSize) { | |
| this.maxSize = maxSize | |
| this.items = new ArrayList(maxSize) |
This file contains hidden or 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 static String camelToSnakeCase(String camelCased) { | |
| def snakeCased = new StringBuilder() | |
| for (char c : camelCased) { | |
| if (c.isUpperCase()) { | |
| snakeCased.append('_') | |
| } | |
| snakeCased.append(c.toLowerCase()) | |
| } |
This file contains hidden or 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
| git log -p -SmyCode -- . | grep -A20 "^\-.*myCode.*$" | cut -c 2- |
NewerOlder