Skip to content

Instantly share code, notes, and snippets.

View 4fuss's full-sized avatar

Adam Kawczyński 4fuss

  • Rotmanka, Polska
View GitHub Profile
@4fuss
4fuss / robot.js
Created December 5, 2012 17:21
Robofuss
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
@4fuss
4fuss / placeholder.scala
Last active August 29, 2015 13:56
Scala's underscore wild card used as placeholder for anonymous functions
val songTitles = List("Lay My Soul to Waste", "Shallow Grave", "Killer by Night", "Cold Dark Mourning")
//passing anonymous function (String => String) to map
songTitles.map(t => t.toLowerCase)
//same using placeholder syntax:
songTitles.map(_.toUpperCase)
@4fuss
4fuss / funcAssignment.scala
Created February 4, 2014 10:39
Predicate and transformation functions
val predicate: (String, Int) => Boolean = { case (_, f) => f > 3 && f < 25 }
val transformFn: (String, Int) => String = { case (w, _) => w }
predicate("lol", 5) //returns true
@4fuss
4fuss / partial.scala
Last active August 29, 2015 13:56
Example of using partial functions in collect doing filtering and mapping in one interation over a sequence.
val wordFrequencies = ("habitaul", 6) :: ("and", 56) :: ("consuetudinary", 2) :: ("additionally", 27) :: ("homely", 5) :: ("society", 13) :: Nil
//verbose implementation - two iterations one for filter and one for map
def wordsWithoutOutliers(wordFrequencies: Seq[(String, Int)]): Seq[String] =
wordFrequencies.filter{case (w, f) => f > 3 && f <25}.map{ case (w,f) => w }
//defining partial function using anonymous function pattern matching
val pf: PartialFunction[(String, Int), String] = {
case (word, freq) if freq > 3 && freq < 25 => word
}
@4fuss
4fuss / dictComp.py
Last active August 29, 2015 13:57
Python dict comprehension
d = {33: "Pipen", 13: "Jordan", 1: "Nobody", 4: "Walker"}
filtr = [33, 4]
{k: v for k, v in d.iteritems() if k in filtr} # {33: 'Pipen', 4: 'Walker'}

Keybase proof

I hereby claim:

  • I am 4fuss on github.
  • I am 4fuss (https://keybase.io/4fuss) on keybase.
  • I have a public key ASBLhmo9Srf1BYTfeMsn-ETG_amQSVgP54lWefsLKqCxtQo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am 4fuss on github.
  • I am 4fuss (https://keybase.io/4fuss) on keybase.
  • I have a public key ASBLhmo9Srf1BYTfeMsn-ETG_amQSVgP54lWefsLKqCxtQo

To claim this, I am signing this object: