Skip to content

Instantly share code, notes, and snippets.

@roundrop
roundrop / MyQuercusServlet.java
Last active August 29, 2015 14:01
QuercusServletの初期化
package jp.roundrop.quercus.servlet;
import com.caucho.quercus.QuercusContext;
import com.caucho.quercus.lib.session.QuercusSessionManager;
import com.caucho.quercus.servlet.QuercusServlet;
import com.caucho.util.Alarm;
import org.slf4j.bridge.SLF4JBridgeHandler;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@roundrop
roundrop / SomeController.scala
Created August 10, 2016 02:45
Skinny Framework の multiParams をバリデーションする
// tags が multiParams
// まず xxxxParams に Seq で入れてしまう
def xxxxParams: Params = {
val title = params.getOrElse("title", "")
val body = params.getOrElse("body", "")
val tags = multiParams.get("tags").getOrElse(Seq()).map(_.trim).distinct.filter(_.nonEmpty)
Params(Map("title" -> title, "body" -> body, "tags" -> tags))
}
// tags についてはカスタムな Seq 用のバリデータ(maxLengths)を適用する
def xxxxForm: MapValidator = validation(xxxxParams,
@roundrop
roundrop / save_gh_issues.sh
Created February 24, 2017 11:27
Save GitHub Issues by curl
#!/usr/bin/env bash
USER=user_name
PERSONAL_TOKEN=*************************************************
USER_OR_ORG=user_name_or_organization_name
REPO=repo_name
# can get per max 100 issues
curl -u $USER:$PERSONAL_TOKEN -o issues_1.json -# https://api.github.com/repos/$USER_OR_ORG/$REPO/issues?state=all\&page=1\&per_page=100
curl -u $USER:$PERSONAL_TOKEN -o issues_2.json -# https://api.github.com/repos/$USER_OR_ORG/$REPO/issues?state=all\&page=2\&per_page=100
@roundrop
roundrop / webhook_recorder.gs
Created November 11, 2022 02:12
App Script that receives webhook requests and records them in a Google Spreadsheet.
function doPost(e) {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
sheet.getRange("1:1").insertCells(SpreadsheetApp.Dimension.ROWS);
sheet.getRange(1, 1).setValue((new Date).toLocaleString('ja-JP'));
sheet.getRange(1, 2).setValue(e.postData.contents);
// send 200 OK status back to confirm receiving webhook
var response = HtmlService.createHtmlOutput();
return response;
import java.net.InetAddress
object CIDRChecker {
/**
* Checks if an IP address is within any of the specified CIDR ranges.
* This method replicates the behavior of PostgreSQL's `<<= ANY` operator for IP addresses.
*
* @param cidrs Array of IP addresses or CIDR notation strings (e.g., "192.168.1.0/24")
* @param address The IP address to check
* @return true if the address is within any of the CIDR ranges, or if the cidrs array is empty.