Skip to content

Instantly share code, notes, and snippets.

View brikis98's full-sized avatar

Yevgeniy Brikman brikis98

View GitHub Profile
@brikis98
brikis98 / BuilderNew.io
Created February 6, 2012 08:03
Seven Languages in Seven Weeks: Io, Day 3
OperatorTable addAssignOperator(":", "atParseHash")
Builder := Object clone do (
indent := ""
atParseHash := method(
key := call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\"")
value := call evalArgAt(1)
" #{key}=\"#{value}\"" interpolate
)
@brikis98
brikis98 / books.prolog
Created February 9, 2012 08:55
Seven Languages in Seven Weeks: Prolog, Day 1
book(a_game_of_thrones).
book(a_clash_of_kings).
book(the_road).
book(flatland).
book(the_adventures_of_sherlock_holmes).
book(one_flew_over_the_cuckoos_nest).
book(the_hitchhikers_guide_to_the_galaxy).
book(the_restaurant_at_the_end_of_the_universe).
book(life_the_universe_and_everything).
var getName = require('name').getName;
exports.hello = function() {
return "Hello " + getName();
};
@brikis98
brikis98 / factorial.prolog
Created February 12, 2012 02:41
Seven Languages in Seven Weeks: Prolog, Day 2
fact(0, 1).
fact(N, Out) :- N > 0, N1 is N - 1, fact(N1, Prev), Out is N * Prev.
@brikis98
brikis98 / slice.prolog
Created February 15, 2012 10:37
Seven Languages in Seven Weeks: Prolog, Day 3
slice([Head | Tail], Slice, Size, Type, I) :-
slice_position(Type, Size, I, X, Y),
insert_into_slice(Head, Slice, X, Y),
I1 is I + 1,
slice(Tail, Slice, Size, Type, I1).
@brikis98
brikis98 / cleo_rest_add_element.txt
Created March 1, 2012 20:02
Cleo: the open source technology behind LinkedIn typeahead search
curl -v -X POST -H "Content-type: application/xml" -H "Accept: application/xml" http://localhost:8080/cleo-primer/rest/elements/_ -d '
<element>
<id>1063</id>
<name>Google Inc. (GOOG)</name>
<title>Technology - Computer Software: Programming Data Processing</title>
<url>http://www.nasdaq.com/symbol/goog</url>
<score>159350</score>
<term>google</term>
<term>inc.</term>
<term>goog</term>
@brikis98
brikis98 / ScalaReduceDocumentation.txt
Created March 18, 2012 06:29
Seven Languages in Seven Weeks: Scala, Day 1
def reduce [A1 >: A] (op: (A1, A1) ⇒ A1): A1
Reduces the elements of this sequence using the specified associative binary operator.
The order in which operations are performed on elements is unspecified and may be nondeterministic.
Note this method has a different signature than the reduceLeft and reduceRight methods of the trait Traversable. The result of reducing may only be a supertype of this parallel collection's type parameter T.
@brikis98
brikis98 / Censor.scala
Created March 19, 2012 07:01
Seven Languages in Seven Weeks: Scala, Day 2
import collection.mutable.HashMap
trait Censor {
val curseWords = new HashMap[String, String]()
io.Source.fromFile("censor.txt").getLines().foreach { (line) =>
val parts = line.split(": ")
curseWords += parts(0) -> parts(1)
}
@brikis98
brikis98 / crawler.scala
Created April 1, 2012 20:05
Seven Languages in Seven Weeks: Scala, Day 3
import io.Source
import scala.actors.Actor._
// Regex to pick up external links; very simplified, so it'll miss some
val linkRegex = "(?i)<a.+?href=\"(http.+?)\".*?>(.+?)</a>".r
object PageLoader {
def load(url: String) = {
try {
Source.fromURL(url).mkString
@brikis98
brikis98 / shirt-front-part1.js
Created April 11, 2012 00:19
[in]tern shirt
var summer = {
i: {
interned: function(callback) {
IN
.API
.Raw("/companies/1337:(id,name,website-url,location,twitter-id,ticker)")
.method("get")
.result(callback);
}
}