Skip to content

Instantly share code, notes, and snippets.

View pirosuke's full-sized avatar

Hiroki Tanaka pirosuke

  • Japan
View GitHub Profile
@kzar
kzar / ssh-tunnel.clj
Created December 7, 2011 16:57
Open and keep open a SSH tunnel using Clojure
(ns ssh-tunnel.core
(require [clj-ssh.ssh :as ssh]))
(defn ssh-tunnel
"Run a ssh tunnel in a deamon thread."
[session local-port remote-port]
(ssh/with-local-port-forward [session local-port remote-port]
(.setDaemonThread session true)
(ssh/with-connection session
(.setServerAliveInterval session 1000)
@jerrypnz
jerrypnz / test_watchers.clj
Created November 6, 2012 09:33
Clojure wrapper for Java 7 WatchService (java.nio.files)
(load-file "./watch_service.clj")
(refer 'watch-service)
(defn print-ev
[ev ctx]
(println "[foo]" ev " --> " ctx)
(println "Parent Dir:" (.getParent ctx)))
(defn print-ev-2
[ev ctx]
@chilversc
chilversc / gist:5575617
Created May 14, 2013 12:47
Connection to MySql from .net over an SSH tunnel, using http://nuget.org/packages/SSH.NET/
void Test()
{
var ci = new ConnectionInfo ("remoteserver", "remoteuser", new PasswordAuthenticationMethod ("remoteuser", "password"));
var cs = new MySqlConnectionStringBuilder ();
cs.AllowBatch = true;
cs.Server = "127.0.0.1";
cs.Database = "database";
cs.UserID = "dbuser";
cs.Password = "dbpassword";
/* require XLSX */
var XLSX = require('XLSX')
function datenum(v, date1904) {
if(date1904) v+=1462;
var epoch = Date.parse(v);
return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
}
function sheet_from_array_of_arrays(data, opts) {
// To subscribe to an event, pass this JSON text to the client through the WebSocket:
{
"body": {
"eventName": "NameOfEvent" // Replace with an event name listed below
},
"header": {
"requestId": "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx", // UUID
"messagePurpose": "subscribe",
"version": 1, // Protocol version (currently 1 as-of 1.0.2)
@youkinjoh
youkinjoh / extendJSON.md
Last active March 9, 2022 07:37
JSONが対応していない値(NaN/Infinity/Date等)をJSONに保存する方法

JSONが対応していない値をJSONに保存する方法

JSONは NaN / Infinity / -InfinityDate 型等に対応していない。 しかし、JavaScriptのJSONは、これらを解消する仕組みを持っている。 それは JSON.parse の第二引数の reviverJSON.stringify の第二引数の replacer だ。

注意が必要なのは、 Date 型は toJSON メソッドを持つため replacer に値が渡る前に文字列になってしまうこと。 これに対応するには toJSON メソッドを一時退避してしまえば良い。

これらを上手く駆使すれば、JSONに型を保ったまま値を保存し復元することができる。