Skip to content

Instantly share code, notes, and snippets.

View vega113's full-sized avatar

Yuri Z. vega113

  • Ramat Gan, Israel
  • 21:11 (UTC +03:00)
View GitHub Profile
@vega113
vega113 / JavaDateThreadSafetyExample.java
Last active October 6, 2017 12:45
Example of Java 6/7 threaf safety issue with SimpleDateFormat.
package com.yuri.java8.time;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by yuri.zelikov on 1/11/2016.
@vega113
vega113 / reader.scala
Created January 6, 2016 07:59
Complementary code for introduction of the Reader in "Dead simple dependency injection video https://youtu.be/ZasXwtTRkio "
package me.reader
/**
* Created by yuri.zelikov on 1/6/2016.
*/
case class Reader[C, A](g: C => A) {
def apply(c: C) = g(c)
def map[B](f: A => B): Reader[C, B] = { c: C =>
Verifying that +vega113 is my blockchain ID. https://onename.com/vega113
@vega113
vega113 / daemon
Created March 4, 2014 12:59
Bash script that given a script runs it as a daemon
#!/bin/bash
#
#
#
# Start on runlevels 3, 4 and 5. Start late, kill early.
# chkconfig: 345 95 05
#
#
#!/bin/bash
@vega113
vega113 / TitleHelper
Created January 21, 2014 20:57
Another version of extractTitle for TitleHelper - not tested.
public static String getTitle(WaveId waveId, WaveletId waveletId, WaveMap waveMap,
ConversationUtil conversationUtil) {
String title = "";
WaveViewData wave =
AbstractSearchProviderImpl.buildWaveViewData(waveId, Lists.newArrayList(waveletId),
SolrSearchProviderImpl.matchesFunction, waveMap);
OpBasedWavelet wavelet = OpBasedWavelet.createReadOnly(wave.getWavelet(waveletId));
if (WaveletBasedConversation.waveletHasConversation(wavelet)) {
@vega113
vega113 / Extend.scala
Created November 30, 2013 06:52
Extend existing companion object
implicit class FutureCompanionOps(f: Future.type) extends AnyVal {
def userInput(message: String): Future[String] = Future {
readLine(message)
}
}
class FutureCompanionOps(f: Future.type) extends AnyVal {
def userInput(message: String): Future[String] = Future {
readLine(message)
package quickcheck
import common._
import org.scalacheck._
import Arbitrary._
import Gen._
import Prop._
abstract class QuickCheckHeap extends Properties("Heap") with IntHeap {
@vega113
vega113 / recfun.scala
Created September 23, 2013 05:12
Assignment Week 1: Functions & Evaluations
package recfun
import common._
object Main {
def main(args: Array[String]) {
println("Pascal's Triangle")
for (row <- 0 to 10) {
for (col <- 0 to row)
print(pascal(col, row) + " ")
println()
@vega113
vega113 / gist:4545324
Created January 16, 2013 07:40
Source for viewhits gadget
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="View Hits" width="72" height="25">
<Require feature="wave" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<div>
@vega113
vega113 / DeltaStoreBasedWaveletState.java
Created October 10, 2011 18:43
A snippet with sample method modified to return ListebaleFuture
class DeltaStoreBasedWaveletState implements WaveletState {
// Some more declarations.
** Executor to evaluate results from future when they become ready. */
private final Executor continuationExecutor = Executors.newSingleThreadExecutor();
/** Keyed by appliedAtVersion. */
private final ConcurrentMap<HashedVersion, ByteStringMessage<ProtocolAppliedWaveletDelta>>
appliedDeltasToPersist =
new ConcurrentHashMap<HashedVersion, ByteStringMessage<ProtocolAppliedWaveletDelta>>();