Skip to content

Instantly share code, notes, and snippets.

View alaz's full-sized avatar

Alexander Azarov alaz

View GitHub Profile
us.rdx2.lgtvsdp.com
us.info.lgsmartad.com
us.ibs.lgappstv.com
us.lgtvsdp.com
ad.lgappstv.com
smartshare.lgtvsdp.com
ibis.lgappstv.com
# added after fork
# from https://www.reddit.com/r/pihole/comments/6qmpv6/blacklists_for_lg_webos_tvs/ and others
@alaz
alaz / readfile.js.es6
Last active January 7, 2017 16:00 — forked from depeele/gist:66656a73bf53773ae852f6613ae05876
HackerRank Javascript stdin using an ES6 generator and larger buffer
'use strict';
function* readLine(stream) {
const EOL = require('os').EOL;
const Fs = require('fs');
const buf = new Buffer(1024);
stream.resume();
stream.setEncoding('ascii');
@alaz
alaz / blocking.scala
Last active April 4, 2016 09:39 — forked from jessitron/gist:8777503
The magic of blocking { ... } in Scala's global ExecutionContext: it leads to the creation of more threads, so the CPUs don't get bored
val des = scala.concurrent.ExecutionContext.global
import scala.concurrent._
import duration._
def ct = Thread.currentThread.getName
val n = Runtime.getRuntime.availableProcessors
def hogThread(sec:Int) = future {
trait PostStart { actor: Actor =>
def postStart: Unit
override def preStart {
super.preStart
actor.become {
case "PostStart" => try { postStart } finally { actor.unbecome }
}
actor.self ! "PostStart"
}
// import for MongoDB Scala Driver
import com.osinka.mongodb._ // <- this replaces Preamble
import com.osinka.mongodb.shape._
import com.mongodb.{Mongo,DBObject}
// Scala complains you are using "case class" here and I understand it. "class" is more
// appropriate as you have no arguments
class User extends MongoObject {
var id: Int = _
var name: String = _
@alaz
alaz / nginx.conf
Created March 6, 2010 15:44 — forked from johnthethird/nginx.conf
Edits and comments to the Nginx config for Riak
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;
case class Word(word: String, count: Long) {
override def toString = word + ": " + count
def +(n: Long): Word = Word(word, count + n)
}
private def showWordCloud {
val words = statusTableModel.filteredStatuses.flatMap(_.text.split("\\s"))
val emptyMap = immutable.Map.empty[String, Word].withDefault(w => Word(w, 0))
val counts = words.foldLeft(emptyMap)((map, word) => map(word) += 1)
val countList = counts.values.toList.sort(_.count > _.count)
// Sketch of an immutable domain model in Scala
// We used this scheme together with this JPA module:
// http://github.com/jboner/skalman/blob/d1e03a85be3964b9012f9e79dd726b0546342b2b/core/src/main/scala/JPA.scala
// ...and this GenericRepository:
// http://github.com/jboner/skalman/blob/d1e03a85be3964b9012f9e79dd726b0546342b2b/core/src/main/scala/GenericRepository.scala
abstract class Entity[T](val id: Int)
object User {