Skip to content

Instantly share code, notes, and snippets.

@davidrapin
davidrapin / create_graph.sql
Last active July 5, 2024 11:58
Start Oracle on macOS (intel) via Docker
# source: https://docs.oracle.com/en/database/oracle/property-graph/24.2/spgdg/getting-started-pgql.html
# source: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-TABLE.html
# list databases
# SELECT ora_database_name from dual;
# show table cols
# DESC all_tables;
# create a graph
@davidrapin
davidrapin / install-fips.sh
Last active March 28, 2024 15:22
Install FIPS for Node.js
#!/bin/bash
set -e
# resources:
# https://github.com/openssl/openssl/blob/master/README-FIPS.md#installing-the-fips-provider-and-using-it-with-the-latest-release
# https://nodejs.org/docs/latest/api/all.html#all_crypto_fips-mode
# https://nodejs.org/api/cli.html#--enable-fips
# parse command line options
if [ -z "$1" ]; then
@davidrapin
davidrapin / !generate_edge_types.cypher
Created March 5, 2021 10:15
Generate edge types (Neo4j Cypher)
// edgeCount: the number of edges with a unique edge-type to generate
// sourceNodeId: ID of the node to be used as source for all generated edges
// targetNodeId: ID of the node to be used as target for all generated edges
// prefix: the edge-type prefix to use for generated edge-types
WITH 100 as edgeCount, 1 as sourceNodeId, 2 as targetNodeId, "edge_type_prefix_" as prefix
MATCH (a), (b) WHERE id(a) = sourceNodeId and id(b) = targetNodeId
WITH range(1, edgeCount) as xx, a, b
UNWIND xx AS x
CALL apoc.create.relationship(a, prefix + toString(x), {property: x}, b) YIELD rel
@davidrapin
davidrapin / !random-dates.cypher
Last active May 5, 2022 03:21
Create random dates (Neo4j Cypher)
// amount: number of random dates to create
// startYear: year range start
// startYear: year range end
WITH 1000 as amount, 2017 as startYear, 2021 as endYear
WITH range(1, amount) as xx, startYear, (endYear - startYear) as yearRange
UNWIND xx as x
WITH date({
year:toInteger(1+startYear+floor(rand()*yearRange)),
month:toInteger(1+floor(rand()*12)),
@davidrapin
davidrapin / !Clean_Silver_Sparrow.md
Last active February 24, 2021 22:39
Detect & Remove Silver Sparrow

What is Silver Sparrow?

https://redcanary.com/blog/clipping-silver-sparrows-wings/

Running the cleaner

Past this in a Terminal window:

curl -s https://gist.githubusercontent.com/davidrapin/f74010691e9a08ab9ca225949e622bba/raw/03d1927c01178bd44416da70f464a2d8a34d8b52/ssp-clean.sh | bash -s --
@davidrapin
davidrapin / start-unifi-app.sh
Last active February 24, 2021 22:40
Start UniFi app (OSX)
# go to correct home folder (itgerwise tomcat will fail)
cd /Applications/UniFi.app/Contents/Resources/
# start unify app with correct java-home (java8 needed)
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/ java -jar /Applications/UniFi.app/Contents/Resources/lib/ace.jar ui &
# open your browseron the local server
open https://localhost:8443
@davidrapin
davidrapin / hash-modulo.js
Last active February 6, 2018 18:37
Hash modulo
// from https://www.npmjs.com/package/sha1
var sha1 = require("sha1")
// compute (sha1) hash modulo
function hash_modulo(str, modulo) {
// ignore case of input
str = str.toUpperCase();
// compute sha1 of input
let h = sha1(str);
// use only the 8 last bytes (4 last hex chars) of the sha1
@davidrapin
davidrapin / index.html
Last active October 12, 2017 17:00
Simple D3 histogram
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
border: 1px solid red;
}
</style>
@davidrapin
davidrapin / howto.md
Created November 21, 2016 16:48
store TypeScript type metadata for runtime check

sauce

You should be able to use the TypeChecker API from the compiler to get to the type information you need. there is no serialization logic readily available, but should be possible to add one.

Here is the TypeChecker API: https://github.com/Microsoft/TypeScript/blob/085f0df4556801c14a4333d6c1d0bab1375586e4/lib/typescript.d.ts#L1027-L1057

Documentation on using the compiler API: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API

Here is the part of the emitter that emitts this infromation today using the Checker: https://github.com/Microsoft/TypeScript/blob/085f0df4556801c14a4333d6c1d0bab1375586e4/src/compiler/emitter.ts#L5065-L5104

@davidrapin
davidrapin / main.js
Created April 4, 2016 16:08
NodeJS module security
// this is a work-in-progress (currently broken), don't use it as-is.
function patchRequire(verbose) {
var Module = require('module');
var originalRequire = Module.prototype.require;
var SENSITIVE_MODULES = ['fs', 'child_process', 'cluster', 'vm'];
var stack = [];
/**
* @param {string} moduleId Package id