Skip to content

Instantly share code, notes, and snippets.

@simlu
simlu / geo-merge-holeless.js
Created April 10, 2021 05:09
Merge polygons and exclude holeless, self-intersecting polygons
const assert = require('assert');
const polygon = require('turf-polygon');
const point = require('turf-point');
const { default: distance } = require('@turf/distance');
const { default: union } = require('@turf/union');
const difference = require('@turf/difference');
const merge = (polygons) => polygons.reduce((p, c) => union(p, polygon([c])), polygon([]));
const normalize = (poly, ...holes) => [holes.reduce((p, h) => {
@simlu
simlu / gist:2f9ebc4cf24e6ceb90fb578a291b3a9c
Created January 20, 2019 04:15
JAVA vs PHP aes gcm adae
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
public class T {
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
private static String bytesToHex(byte[] bytes) {
@simlu
simlu / make-files-unique.js
Created August 22, 2018 00:55
Make files unique, ignoring different string / number value in object hierarchy
const fs = require("fs");
const path = require("path");
const get = require("lodash.get");
const set = require("lodash.set");
const objectScan = require("object-scan");
const objectHash = require("object-hash");
const data = Object.entries(fs.readdirSync(path.join(__dirname, "query"))
.map(f => f.slice(0, -5))
.reduce((p, f) => Object.assign(p, {
@simlu
simlu / npm-offline-cache.js
Last active July 1, 2018 21:09
NPM Offline Cache Experiment
// Unfortunately this doesn't work as expected (NPM is broken as usual)
const os = require("os");
const fs = require("fs");
const path = require("path");
const { execSync, exec } = require('child_process');
const async = require("async");
const objectScan = require("object-scan");
const get = require("lodash.get");
const difference = require("lodash.difference");
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cloudformation:Describe*",
"cloudformation:List*",
"cloudformation:Get*",
"cloudformation:PreviewStackUpdate",
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cloudformation:Describe*",
"cloudformation:List*",
"cloudformation:Get*",
"cloudformation:PreviewStackUpdate",