This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import asyncio | |
async def fetch(session, url): | |
async with session.get(url) as response: | |
return await response.text() | |
async def main(): | |
async with aiohttp.ClientSession() as session: | |
results = [wait_for_code(404, session, 'http://python.org') for i in range(2)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
# generate some example data | |
matrix = [[1,2,3,4,5,6,7,8,9,10],[1,1,1,1,1,1,1,1,1,1],[5,5,5,5,5,5,5,5,5,5]] | |
# plot the matrix as an image with an appropriate colormap | |
plt.imshow(matrix, aspect='auto', cmap="bwr") | |
# add the values | |
for nrow in range(0,len(matrix)): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# There can only be a single job definition per file. This job is named | |
# "example" so it will create a job with the ID and Name "example". | |
# The "job" stanza is the top-most configuration option in the job | |
# specification. A job is a declarative specification of tasks that Nomad | |
# should run. Jobs have a globally unique name, one or many task groups, which | |
# are themselves collections of one or many tasks. | |
# | |
# For more information and examples on the "job" stanza, please see | |
# the online documentation at: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.doorchoice | |
import scala.util.Random | |
import akka.actor._ | |
import com.doorchoice.DoorChoice.{SwitchingStrategy, GameStrategyRunner, StickingStrategy} | |
import akka.util.Timeout | |
import akka.actor.Terminated | |
import java.util.concurrent.TimeUnit | |
object DoorChoice { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait BValue { | |
def encode: String | |
} | |
case class BInt(value: Int) extends BValue{ | |
lazy val encode = "i" + value + "e" | |
} | |
case class BString(value: String) extends BValue{ | |
lazy val encode = value.size + ":" + value | |
} | |
case class BList(values: BValue*) extends BValue{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BigDecimalMath { | |
implicit def toBigDecimal(decimal: String): BigDecimal = BigDecimal(decimal) | |
def sqrt(x: BigDecimal): BigDecimal = { | |
val maxIterations = x.mc.getPrecision + 1 | |
val guessSteam: Stream[BigDecimal] = newtonRaphsonApproximations(x).take(maxIterations) | |
val exactMatch: Option[Stream[BigDecimal]] = guessSteam.sliding(2).find(a => a(0) == a(1)) | |
val root: Stream[BigDecimal] = exactMatch.getOrElse(Stream(guessSteam.last)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Observable<EsperEvent> sendDisconnectOnUnsubscribe(final Observable<EsperEvent> responseForThisRequest, | |
final CreateEventStreamRequest createEventStreamRequest) { | |
return Observable.create(new Func1<Observer<EsperEvent>, Subscription>() { | |
@Override | |
public Subscription call(final Observer<EsperEvent> esperEventObserver) { | |
final Subscription wrapped = responseForThisRequest.subscribe(new Action1<EsperEvent>() { | |
@Override | |
public void call(EsperEvent esperEvent) { | |
esperEventObserver.onNext(esperEvent); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.oxlade39.vaadin; | |
import org.joda.time.DateTime; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import rx.Observable; | |
import rx.subjects.Subject; | |
import java.util.concurrent.ScheduledExecutorService; | |
import java.util.concurrent.TimeUnit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val bufferedReader = new BufferedReader(new InputStreamReader(inputstream)) | |
val responseStream: Enumerator[String] = Enumerator.generateM[String] { | |
Future{ | |
logger.trace("about to read line") | |
val line: String = bufferedReader.readLine() | |
logger.trace("read line") | |
Option(line) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Delete generated _site files' | |
task :clean do | |
system "rm -fR _site2" | |
system "git submodule update" | |
system "cd _site && git checkout master . && git clean -d -f" | |
end | |
desc 'Run the jekyll dev server' | |
task :server do | |
system "jekyll --server" |
NewerOlder