Skip to content

Instantly share code, notes, and snippets.

@mostr
mostr / SimpleSpec.scala
Created April 7, 2021 08:52
ZIO test clock + scheduled tasks
package scheduler
import zio.clock.Clock
import zio.duration.durationInt
import zio.logging.Logging
import zio.test.Assertion.equalTo
import zio.test.environment.TestEnvironment
import zio.test.{DefaultRunnableSpec, ZSpec}
import zio.{Has, Ref, ZIO}
@mostr
mostr / AkkaRefsSerializationOps2.scala
Created November 30, 2019 14:45
Akka references serialization with Protobufs - 2
// allow serialization of akka goodies, e.g. streamrefs that we use
object AkkaRefsSerializationOps {
def toProtoPayload(akkaRefToSerialize: AnyRef)(implicit system: ActorSystem): SerializedAkkaPayload = {
val ext = SerializationExtension(system)
val serializer = ext.findSerializerFor(akkaRefToSerialize)
val manifest = Serializers.manifestFor(serializer, akkaRefToSerialize)
Serialization.withTransportInformation(ext.system) { () =>
val sinkSerialized = ByteString.copyFrom(serializer.toBinary(akkaRefToSerialize))
SerializedAkkaPayload(sinkSerialized, manifest, serializer.identifier)
@mostr
mostr / AkkaRefsSerializationOps1.scala
Created November 30, 2019 14:45
Akka references serialization with Protobufs - 1
// allow serialization of akka goodies, e.g. streamrefs that we use
object AkkaRefsSerializationOps {
def toProtoPayload(akkaRefToSerialize: AnyRef)(implicit system: ActorSystem): SerializedAkkaPayload = {
val ext = SerializationExtension(system)
val serializer = ext.findSerializerFor(akkaRefToSerialize)
val manifest = Serializers.manifestFor(serializer, akkaRefToSerialize)
val sinkSerialized = ByteString.copyFrom(serializer.toBinary(akkaRefToSerialize))
SerializedAkkaPayload(sinkSerialized, manifest, serializer.identifier)
}
### Keybase proof
I hereby claim:
* I am mostr on github.
* I am mostr (https://keybase.io/mostr) on keybase.
* I have a public key ASCitYdI7ovaxK2rQQi5aTi7VB5996vLDPEusIU6QF3lUwo
To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am mostr on github.
  • I am mostr (https://keybase.io/mostr) on keybase.
  • I have a public key ASBmVbAQ_Boa-EMLXQreBsxuGk1Qk2PfXKwL2jL3_1qjzgo

To claim this, I am signing this object:

@mostr
mostr / TestToken.sol
Created May 2, 2018 09:46
Test ERC20 token contract
pragma solidity ^0.4.16;
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
contract TestToken is StandardToken {
constructor(uint256 _initialBalance) public payable {
balances[msg.sender] = _initialBalance;
}
@mostr
mostr / App.js
Last active March 23, 2017 08:08
State mgmt
import React from 'react';
import {connect} from './statemgmt';
import * as actions from './actions';
const App = () => <Counter/>
export default App;
function _Counter(props) {
return (
@mostr
mostr / logtest.js
Last active January 18, 2017 15:05
Winston wrapper
let winston = require('winston');
// instantiate winston logger
// configure rewriters to add TID and application name to "meta"
// ...
function wrapWinston(logger) {
return ['debug', 'warn', 'info', 'error'].reduce((res, e) => {
res[e] = function(msg, ...extras) {
@mostr
mostr / example.jsx
Created October 10, 2016 10:37
MobX observer that allows passing function selector
import React from 'react';
import ReactDOM from 'react-dom';
import * as mobx from 'mobx-react';
import {state, actions} from './store';
// passing function to observer (with implicit inject) is not supported natively, so make up your own one
// pass either function or plain old selector strings array
// WARNING: doesn't work if "observer" used as decorator
let observer = (selector, Component) => {
@mostr
mostr / code.js
Last active April 7, 2016 11:01
Async functions cannot be used as reducers in sequence
// Lets create some dirs structure (async)
function createDir(name, parent): any {
return new Promise((res, rej) => {
console.log(`Creating ${name} with parent ${parent}`);
res(name);
});
}
const dirsToCreate = ['foo', 'bar', 'baz', 'boo'];