Skip to content

Instantly share code, notes, and snippets.

View goseign's full-sized avatar

Xu Bin goseign

  • Home
  • Mountain view, CA
View GitHub Profile
@goseign
goseign / 0_reuse_code.js
Last active August 29, 2015 14:23
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@goseign
goseign / simple-promise-retry.js
Created June 5, 2018 20:13 — forked from briancavalier/simple-promise-retry.js
A few general patterns for retries using promises
function keepTrying(otherArgs, promise) {
promise = promise||new Promise();
// try doing the important thing
if(success) {
promise.resolve(result);
} else {
setTimeout(function() {
keepTrying(otherArgs, promise);
@goseign
goseign / layout.scala
Created June 21, 2018 18:15 — forked from rjurney/layout.scala
Disappearing labels when I run the fix to make the Label Adjust overlap work
import java.awt.Color
import java.io.File
import java.io.IOException
import org.gephi.data.attributes.api.AttributeColumn
import org.gephi.data.attributes.api.AttributeController
import org.gephi.data.attributes.api.AttributeModel
import org.gephi.filters.api.FilterController
import org.gephi.filters.api.Query
import org.gephi.filters.api.Range
import org.gephi.filters.plugin.graph.DegreeRangeBuilder.DegreeRangeFilter

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@goseign
goseign / FindNonexistentFile.scala
Created August 22, 2018 23:53 — forked from halfninja/FindNonexistentFile.scala
Useful Scala snippets
def newTempFile() = new File(IoTmpDir, "JavaTestTmp-"+random.nextLong())
/*
* Tries 10 times to find a nonexistent file.
* Uses Streams to lazily go through a range, generating a fresh
* file each time.
*/
val dir = Stream.range(1,10)
.map { newTempFile() }
.find(!_.exists)
@goseign
goseign / 46f00aff2ed_2.scala
Created August 24, 2018 17:45 — forked from phantomastray/46f00aff2ed_2.scala
46f00aff2ed word search problem
case class GridCell(x: Int, y: Int)
def exist(board: Array[Array[Char]], word: String): Boolean = {
val deltaVector = List((0, -1), (0, 1), (1, 0), (-1, 0))
def inBounds(cell: GridCell) = cell.x >= 0 && cell.x < board.length && cell.y >= 0 && cell.y < board(0).length
def dfs(word: List[Char], currentCell: GridCell, visited: List[GridCell]): Boolean = {
word match {
final case class User private[domain] (userId: UserId, createdAt: Instant, name: String, email: Email) {
def applyEvent(userEvent: UserEvent): Try[User] = userEvent match {
case _: UserCreated => Failure(new IllegalStateException("User already created. Event cannot be applied."))
case event: NameUpdated => Success(copy(name = event.newName))
case event: EmailUpdated => Success(copy(email = event.newEmail))
}
def process(userCommand: UserCommand): Try[List[UserEvent]] = userCommand match {
case _: CreateUser => Failure(new IllegalStateException("User already created. Command cannot be processed."))
@goseign
goseign / EventSourcing.scala
Created October 23, 2018 23:42 — forked from szoio/EventSourcing.scala
Event Sourcing with Free Monads
package eventsourcing
import java.time.Instant
import cats._
import cats.data.Coproduct
import cats.free.{Free, Inject}
import cats.implicits._
import doobie.imports._
import fs2.Stream
@goseign
goseign / Scheduling.scala
Created February 22, 2019 18:15 — forked from hochgi/Scheduling.scala
scala scheduling with akka
import akka.actor.{ActorSystem, Scheduler}
import com.astoncap.util.concurrent.Async._
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.util.Try
trait Scheduling {
implicit val scheduling: Scheduling = this
@goseign
goseign / ValidationResultLib.scala
Created April 11, 2019 06:11 — forked from dzikowski/ValidationResultLib.scala
A micro-library for data validation over cats.Monad and cats.data.EitherT
package com.softwaremill.monadvalidation.lib
import cats.Monad
import cats.data.EitherT
import scala.language.higherKinds
trait ValidationResultLib[M[_]] {
type ValidationResult[F, S] = EitherT[M, F, S]