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
| // Branch and bound knapsack problem | |
| import collection.mutable.PriorityQueue | |
| /** This class represents a thing we can put in the napsack. | |
| */ | |
| class Thing(wIn:Int, vIn:Int) extends Ordered[Thing] { | |
| val w = wIn | |
| val v = vIn | |
| def v_w = v / w | |
| override def toString = "w=%d, v=%d, v/w=%d".format(w, v, v_w) |
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
Show hidden characters
| { | |
| "caret_style": "phase", | |
| "color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme", | |
| "default_line_ending": "unix", | |
| "draw_white_space": "all", | |
| "ensure_newline_at_eof_on_save": true, | |
| "font_face": "ProggySquareTT", | |
| "font_size": 12, | |
| "line_padding_bottom": 1, | |
| "rulers": |
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
| # Tested on Windows 7 and Python 2.7 | |
| # the code | |
| def lagrangian_interpolate(samples): | |
| """ | |
| Takes some samples as a list of tuples and returns a function that's | |
| a lagrangian interpolation of all the samples. | |
| """ | |
| X = 0 # the tuple index of the X variable in the samples | |
| Y = 1 # the tuple index of the Y variable in the samples |
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
| def super_split(string, delim): | |
| segment = '' | |
| for c in string: | |
| if c in delim: | |
| yield segment | |
| segment = '' | |
| else: | |
| segment += c | |
| yield segment |
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 mechanize | |
| from BeautifulSoup import BeautifulSoup | |
| class Dmoz(object): | |
| def __init__(self): | |
| self.br = mechanize.Browser() | |
| def get_page_urls(self, term): | |
| result = self.br.open("http://www.dmoz.org/search?q="+term) | |
| result_html = result.read() |
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 AdjacencyMatrix[T: Manifest](size: Int) { | |
| // initialize it | |
| // (It's in column vector format) | |
| val matrix = Array.ofDim[T](size, size) | |
| // helper functions | |
| // takes a list of 3-tuples in the form: (from, to, weight) | |
| def setConnections(connections: List[(Int, Int, T)]) = { | |
| for (x <- connections) { | |
| // make matrix[to][from] = weight |
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
| #include <stdio.h> | |
| double my_ceil(double x) { | |
| double y = (double) ((long long) x); | |
| if (x - y == 0) { | |
| return x; | |
| } else { | |
| if (x > 0) { | |
| return y + 1; | |
| } else { |
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
| The first is to use the object oriented way: | |
| $config = array( | |
| 'indent' => true, | |
| 'output-xml' => true, | |
| 'wrap' => 200); | |
| // Tidy | |
| $tidy = new tidy; | |
| $tidy->parseString($xml, $config, 'utf8'); | |
| $tidy->cleanRepair(); |
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
| <?php | |
| /** | |
| * Intelligent News Parser Library | |
| * | |
| * @package Parse_news | |
| * @category Libraries | |
| * @author Mark Watson | |
| * @link http://markwatson.us | |
| * | |
| * A simple library that parses the html from news articles to pull out metadata. |
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
| <?php | |
| /** | |
| * The global model! All hail potentate MY_Controller! | |
| * It provides some great default queries... | |
| */ | |
| class MY_Model extends Model | |
| { | |
| var $default_table; | |
| function get_all() |