Skip to content

Instantly share code, notes, and snippets.

@gzoller
gzoller / MyPhase.scala
Created December 2, 2022 21:33
Attempting to override a method in plugin
class MyPhase extends PluginPhase {
import tpd._
val phaseName = "overrider"
override val runsAfter = Set(Pickler.name)
override def transformTypeDef(tree: TypeDef)(implicit ctx: Context): Tree =
if tree.isClassDef && !tree.rhs.symbol.isStatic then // only look at classes & traits, not objects
@gzoller
gzoller / ClassDefModification.scala
Created November 29, 2022 20:16
Scala Compiler Plugin ClassDef Modificaiton
class ReflectionWorker extends StandardPlugin {
val name: String = "reflectionWorker"
override val description: String = "heavy-lift reflection worker"
def init(options: List[String]): List[PluginPhase] =
new ReflectionWorkerPhase :: Nil
}
class ReflectionWorkerPhase extends PluginPhase {
import tpd._
@gzoller
gzoller / E90_KOMBI_control
Created September 19, 2021 18:02
Controlling E90 Instrument Cluster (tachometer) via CAN bus (CANBed module)
#include <mcp_can.h>
#include <SPI.h>
#define lo8(x) (uint8_t)((x) & 0xFF)
#define hi8(x) (uint8_t)(((x)>>8) & 0xFF)
const int SPI_CS_PIN = 17; // CANBed V1
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
uint8_t checkSum = 0xE2;
package co.blocke.reflect
import scala.tasty.file._
import scala.tasty.Reflection
object Main extends App {
val p = Person("Fred", 53)
ReflectClass.showInfo(p)
case class SpeedGraphRC(system: ActorSystem, host: String, groupId: String, topic: String) extends GraphHolder[String] {
val count = new LinkedBlockingQueue[Int]()
val flow = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder: GraphDSL.Builder[akka.NotUsed] =>
import GraphDSL.Implicits._
type In = CommittableMessage[Array[Byte], String]
val consumerSettings = ConsumerSettings(system, new ByteArrayDeserializer, new StringDeserializer)
.withBootstrapServers(host)
@gzoller
gzoller / LateProducer.scala
Last active April 16, 2016 18:48
Kafka populate topic
package com.cof.kafka
import scala.collection.JavaConversions._
import org.apache.kafka.clients.producer.{ ProducerRecord, KafkaProducer, Callback, RecordMetadata }
import kafka.admin.AdminUtils
import kafka.utils.ZkUtils
case class LateProducer() {
def populate(num: Int, host: String, topic: String) {
@gzoller
gzoller / KafkaThread.scala
Last active April 16, 2016 18:57
Kafka 0.9.0.1 Consumer
package com.cof.kafka
import org.apache.kafka.common.serialization.{ ByteArrayDeserializer, Deserializer, StringDeserializer }
import java.util.concurrent.LinkedBlockingQueue
import org.apache.kafka.common.TopicPartition
import org.apache.kafka.clients.consumer.{ ConsumerRebalanceListener, OffsetCommitCallback, ConsumerRecord, KafkaConsumer, OffsetAndMetadata }
import scala.concurrent.Promise
import java.util.concurrent.TimeUnit
import scala.collection.JavaConversions._
import scala.concurrent.Await
//---------------------------- build.gradle (Project: gcm)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
@gzoller
gzoller / FlexiFlowExample.scala
Last active November 5, 2018 13:40
Akka Stream FlexiFlow switch example
object PrimaryFlow extends App {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
val sj = ScalaJack()
val graph = FlowGraph.closed() { implicit builder: FlowGraph.Builder[Unit] =>
import FlowGraph.Implicits._
val in = Source(List.empty[String]) // hook this up to RabbitMQ
val out = Sink.foreach( (mc:Command) => println("Command:" +mc) )
root@e427cd230b83:/# cat /var/log/mongodb/mongodb.log
Tue Sep 15 00:01:55 [initandlisten] MongoDB starting : pid=12 port=27017 dbpath=/var/lib/mongodb 64-bit host=e427cd230b83
Tue Sep 15 00:01:55 [initandlisten] db version v2.0.6, pdfile version 4.5
Tue Sep 15 00:01:55 [initandlisten] git version: nogitversion
Tue Sep 15 00:01:55 [initandlisten] build info: Linux z6 3.8-trunk-amd64 #1 SMP Debian 3.8.3-1~experimental.1 x86_64 BOOST_LIB_VERSION=1_49
Tue Sep 15 00:01:55 [initandlisten] options: { command: [ "run" ], config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", journal: "true", logappend: "true", logpath: "/var/log/mongodb/mongodb.log", unixSocketPrefix: "/var/run/mongodb" }
Tue Sep 15 00:01:55 [initandlisten] Assertion: 13651:Couldn't fsync directory '/var/lib/mongodb': errno:22 Invalid argument
0x5d74b3 0x5ddcd9 0x5dc3a9 0x7cc596 0x8d12c3 0x8d22d8 0x58f02c 0x7f42509b8ead 0x58f8e9
/usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x23) [0x5d74b3]
/usr/bin/mongod(_ZN5mongo11msgassertedEiPKc+0xb9) [0x5d