Skip to content

Instantly share code, notes, and snippets.

View maciej's full-sized avatar

Maciej Biłas maciej

View GitHub Profile
@maciej
maciej / waw_suburbs.geojson
Created April 18, 2014 08:51
Warsaw suburbs
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@maciej
maciej / scan-beacons.js
Created April 23, 2014 14:39
NodeJS iBeacon scanner
// Requires NodeJS and "noble" module: https://github.com/sandeepmistry/noble
// Based on: https://github.com/sandeepmistry/noble/issues/62
var noble = require('noble');
noble.on('stateChange', function(state) {
if (state === 'poweredOn' ) {
noble.startScanning([], false);
} else {
noble.stopScanning();
}
@maciej
maciej / ImplicitServiceDepBinding.scala
Created September 6, 2014 12:59
Macwire fails to wire dependencies declared as implicit
import com.softwaremill.macwire.Macwire
class ServiceDependency
class Service(implicit val otherDependency : ServiceDependency)
trait Module extends Macwire {
lazy val otherDependency = new ServiceDependency
lazy val service = wire[Service]
}
@maciej
maciej / SomeActorWithDependency.scala
Created September 9, 2014 12:24
Actors with constructor-passed dependencies
import akka.actor._
object Beans {
lazy val actorSystem = ActorSystem("Hi-Actor")
def depActorFactory(f : ActorRefFactory) = f.actorOf(Props[DepActor])
def someActorFactory = actorSystem.actorOf(Props(classOf[SomeActor], depActorFactory _))
}
@maciej
maciej / BuildTheActors.scala
Last active August 29, 2015 14:07
Akka: build the world
/*
* DI u nas robione jest manualnie.
* W module tworzę factory dla aktorów. Factory są zarówno dla aktorów, którzy są parametryzowani jak i dla tych, co nie są.
* Potem w odpowiednim aktorze mogę wywołać context.actorOf(someActorFactory()) i mam zachowaną hierarchię.
*
* Jak chcesz więcej poczytać o manualnym DI to polecam http://di-in-scala.github.io/
*/
trait ActorsModule extends ActorSystemModule {
/* Te zależności są wmiksowywane z innych modułów */
@maciej
maciej / jh.fish
Created October 20, 2014 23:20
Utility to quickly change the JAVA_HOME in OSX
function jh
if test -e /usr/libexec/java_home
set _jh (/usr/libexec/java_home -v 1.$argv)
if test -n $_jh
echo "Setting JAVA_HOME to $_jh"
set -gx JAVA_HOME $_jh
else
echo "Could not find java version $argv"
end
else
@maciej
maciej / dpw.json
Created March 13, 2015 15:24
dane po warszawsku
{
"values": [
{
"key": "tabor",
"value": "T"
},
{
"key": "linia",
"value": "11"
},
jstack -l 81427
2015-06-03 13:36:09
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode):
"Attach Listener" #36 daemon prio=9 os_prio=31 tid=0x00007fbb9e816800 nid=0x5507 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
import com.softwaremill.thegarden.lawn.base.StringExtensions._
trait SnakeCaseJsonProtocol extends DefaultJsonProtocol {
override protected def extractFieldNames(classTag: ClassTag[_]) = super.extractFieldNames(classTag).map {_.underscore}
override protected def fromField[T](value: JsValue, fieldName: String)(implicit reader: JsonReader[T]) =
super.fromField(value, fieldName.camelCase)(reader)
}
class Picture < ActiveRecord::Base
def self.new_from_flickr_photo(photo)
picture = Picture.new
picture.set_attributes_from_flickr_photo(photo)
picture
end
def set_attributes_from_flickr_photo(photo)
# copy whichever attributes you might need