Skip to content

Instantly share code, notes, and snippets.

View irumiha's full-sized avatar

Igor Rumiha irumiha

View GitHub Profile
@irumiha
irumiha / TodoApp.java
Last active September 17, 2023 15:23
Single-file Spring Boot application. A silly example but it can be done. Run it as `jbang TodoApp.java`. You need the https://www.jbang.dev/ tool installed
//JAVA 17
//DEPS org.springframework.boot:spring-boot-dependencies:3.1.3@pom
//DEPS org.springframework.boot:spring-boot-starter-web
//DEPS org.springframework.boot:spring-boot-starter-data-jdbc
//DEPS com.h2database:h2
package app;
import org.slf4j.Logger;
@irumiha
irumiha / udpconn_permissive.go
Created January 5, 2017 08:47
PermissiveUDPConn is a UDP connection that allows responses to come from a different IP address than the one a packet was sent to.
package snmp
import (
"net"
"os"
"syscall"
"time"
)
// PermissiveUDPConn is a UDP connection that allows responses to come from
@irumiha
irumiha / GameOfLife.scala
Created March 4, 2015 17:29
Game of Life short implementation in Scala
package com.rumi
object GameOfLife {
/**
* Calculate the next iteration of the Game of Life. The game state is
* represented by a Set[(Int,Int)] of alive cells. A new set is generated
* for every generation. Coordinates count from (1,1) to (w,h), while the
* (1,1) cell is in the top left corner.
*
@irumiha
irumiha / Application.scala
Last active January 23, 2017 21:53
play-2.1.0-chat
// This is the part in the Controller that creates the EventSource connection
def liveListen(event: String) = Action { request =>
AsyncResult {
implicit val timeout: Timeout = 5.seconds
(MegaRoomActor.ref ? (MegaRoomActor.Join(event)) ).
mapTo[Enumerator[JsValue]].map(startEventStream)
}
}
package test
import org.specs2.mutable._
import play.api.test._
import play.api.test.Helpers._
class AuthenticationTests extends Specification {
"The authentication system" should {
trait Security {
/**
* Retrieve the connected user email.
*/
private def username(request: RequestHeader) =
request.session.get("username")
/**
* Redirect to login if the user in not authorized.
*/
val Some(r) = routeAndCall(FakeRequest(GET, "/logout").
withSession("username" -> "admin@bigsite"))
@irumiha
irumiha / isitabug.scala
Created May 19, 2011 09:29
Possible scalate/scuery bug
import org.fusesource.scalate.scuery._
object isitabug {
val testinput =
<html>
<head></head>
<body>
<div class="test">
<div class="real">