Skip to content

Instantly share code, notes, and snippets.

@igor-ramazanov
igor-ramazanov / free-monads-kv-store.scala
Last active September 19, 2018 11:11
An example how to compile a higher-level language into a lower-level one with parameterised argument types in Free monads way
package io.github.themirrortruth
object KVStore {
def main(args: Array[String]): Unit = {
import cats.free.Free
import cats.{Id, ~>}
//Strict language for working with abstract key-value stores defined as Algebraic Data Type (ADT)
sealed trait KVStoreApi[Key, Value, Result]
extends Product
@takahirom
takahirom / EventBus.kt
Last active June 9, 2022 10:21
EventBus by Kotlin coroutine
import kotlinx.coroutines.experimental.channels.BroadcastChannel
import kotlinx.coroutines.experimental.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.filter
import kotlinx.coroutines.experimental.channels.map
import kotlinx.coroutines.experimental.launch
import javax.inject.Inject
import javax.inject.Singleton
@fancyerii
fancyerii / ImportModelTest.java
Last active October 24, 2022 14:24
Load Tensorflow Model in Java
package com.easemob.ai.robotapi.test.tensorflow;
import org.tensorflow.SavedModelBundle;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
public class ImportModelTest {
public static void main(String[] args) {
try (SavedModelBundle b = SavedModelBundle.load("/home/mc/data/test-tensorflow/model", "serve")) {
@fancyerii
fancyerii / export.py
Last active April 2, 2018 18:25
python save tensorflow model
import tensorflow as tf
import random as rand
import numpy as np
data=np.reshape(np.random.uniform(0,1, 1000),(1000,1))
label = 2*data+1
# Setting configurations
n_nodes_hl1 = 3 # nodes in hidden layer 1
n_nodes_hl2 = 5 # nodes in hidden layer 2
@roadrunner2
roadrunner2 / 0 Linux-On-MBP-Late-2016.md
Last active May 10, 2024 13:04
Linux on MacBook Pro Late 2016 and Mid 2017 (with Touchbar)

Introduction

This is about documenting getting Linux running on the late 2016 and mid 2017 MPB's; the focus is mostly on the MacBookPro13,3 and MacBookPro14,3 (15inch models), but I try to make it relevant and provide information for MacBookPro13,1, MacBookPro13,2, MacBookPro14,1, and MacBookPro14,2 (13inch models) too. I'm currently using Fedora 27, but most the things should be valid for other recent distros even if the details differ. The kernel version is 4.14.x (after latest update).

The state of linux on the MBP (with particular focus on MacBookPro13,2) is also being tracked on https://github.com/Dunedan/mbp-2016-linux . And for Ubuntu users there are a couple tutorials (here and here) focused on that distro and the MacBook.

Note: For those who have followed these instructions ealier, and in particular for those who have had problems with the custom DSDT, modifying the DSDT is not necessary anymore - se

@nightscape
nightscape / ConvertUtils.scala
Created March 31, 2015 23:46
Parquet to CSV
import ComparisonChain._
import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.Closeable
import java.io.File
import java.io.File
import java.io.FileInputStream
import java.io.FilenameFilter
import scala.collection.mutable.ListBuffer
case class Point(x: Double, y: Double)
/** Compute the convex hull of given points. Returns vertices ordered ccw */
def convexHull(_points: Seq[Point]): Seq[Point] = {
val points = _points.sortBy(_.x)
val upper = halfHull(points)
val lower = halfHull(points.reverse)
upper.remove(0)
@sasaki-shigeo
sasaki-shigeo / gzip-sample.scala
Last active August 26, 2019 14:06
A sample code of gzip in Scala. The API of gzip is defined in the package java.util.zip that provides GZIPOutputStream and GZIPInputStream, the subclasses of DeflatterOutputStream and InflatterInputStream, respectively. GZIPOutputStream compresses data into a given output stream and GZIPInputStream decompresses data from an input one.
import java.io._
import java.util.zip._
val pi = new PipedInputStream
val po = new PipedOutputStream(pi)
val zo = new GZIPOutputStream(po)
val zi = new GZIPInputStream(pi)
val w = new PrintWriter(zo)
val r = new BufferedReader(new InputStreamReader(zi))
@johndrinkwater
johndrinkwater / dualshock-research
Last active March 16, 2024 15:12
I’m interested in writing (or helping to spec out the protocol so someone else can write) the linux kernel driver for Sony’s DualShock 4 (PS4’s lovely controller) Currently using the output of HID RAW from a USB connected dualshock 4… For the gyro/touchpad discovery, I’ve just been using some terrible c code to throw numbers on the screen and it…
TADA, it’s `hexdump -v -e '64/1 "%02x" "\n"' < /dev/hidraw3`
No idea what the first byte is… but I’m going to assume its for device ID for the many users that are connected, but it probably has to be set by the connected machine?
01ff777f7f0800aa0000435dfdf1ff14000200c5ff0721150300000000001b000001fc9133a32990880428008000000080000000008000000080000000008000
↑↑↑↑
left stick, value, first field is horz (00 left), second field is vertical (00 top)
017f80ff61080064000059f2fdfffffbff0e00d107081e9bf600000000001b0000018e94b1b00690880428008000000080000000008000000080000000008000
↑↑↑↑
@drkibitz
drkibitz / gist:6143035
Last active April 23, 2020 16:37
pixi.js IntactionManager Example Usage 2
// create an new instance of a pixi stage
var stage = new PIXI.Stage(0x66FF99);
// create a renderer instance
var renderer = PIXI.autoDetectRenderer(400, 300);
// create a manager instance, passing stage and renderer.view
var manager = new PIXI.InteractionManager(stage, renderer.view);
stage
.on('click', function (event) {
console.log(event.type, event.target); // 'click', PIXI.DisplayObject {}