Skip to content

Instantly share code, notes, and snippets.

@euch
euch / ping 22
Last active October 10, 2022 11:39
Fake 'ping' for TCP-only environments. Return exit 0 if target port 22 is available.
#!/bin/sh
PORT=22
HOST="${BASH_ARGV[0]}"
echo -e Pinging $HOST on port $PORT over TCP
if nc -z -v -w5 $HOST $PORT >/dev/null 2>&1;
then
echo "OK"
@euch
euch / openttd.scala
Created June 29, 2016 10:06
Fetch OpenTTD server statistics from http://openttd.org
def getOpenTTDServerInfoCached(serverName: String): Option[String] = {
val cacheKey = OpenTTDServerInfo(serverName)
reachabilityCache.get(cacheKey) match {
case Some(expired) if expired.time.plusMinutes(1).isBefore(now) => reachabilityCache.update(cacheKey, getOpenTTDServerInfo(cacheKey))
case None => reachabilityCache.put(cacheKey, getOpenTTDServerInfo(cacheKey))
case Some(actual) =>
}
reachabilityCache.get(cacheKey) match {
case Some(info) => info.status
case None => None
List pendingVisits = new LinkedList<>();
Long pendingVisitsRefreshTime = 0L;
public List getPendingVisits() throws QmaticClientException {
Long currentTime = new Date().getTime();
if (!this.pendingVisits.isEmpty() && (currentTime - pendingVisitsRefreshTime <= 10000))
return this.pendingVisits;
this.pendingVisits.clear();
List<VisitInfo> pendingVisitsForCurrentWS = new ArrayList<>();
@euch
euch / TableGenerator.java
Created May 22, 2012 14:06
TableGenerator (ejb → html)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.taskmanager.servlet;
import com.mycompany.taskmanager.ejb.RelationFacadeLocal;
import com.mycompany.taskmanager.ejb.Task;
import com.mycompany.taskmanager.ejb.TaskFacadeLocal;
import com.mycompany.taskmanager.ejb.Time;
@euch
euch / zshrc
Created January 9, 2012 11:10
new tiny zshrc
#!/bin/zsh
# completion
autoload -U compinit
compinit
zstyle ':completion:*' menu select
setopt MENU_COMPLETE
# correction
" Open URL in browser
function! Browser ()
let line = getline (".")
let line = matchstr (line, "http[^ ]*")
exec "!chromium ".line
endfunction