Skip to content

Instantly share code, notes, and snippets.

@emrul
emrul / E4X.java
Last active August 29, 2015 14:18 — forked from tuchida/E4X.java
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class E4X {
public static void main(String[] args) {
System.out.println("E4X: " + System.getProperty("nashorn.lexer.xmlliterals"));
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
try {
@emrul
emrul / README.md
Created March 16, 2016 00:04 — forked from lovasoa/README.md
Compute the intersection of large arrays in javascript

Array intersect

Fastest function to intersect a large number of big arrays in javascript, without dependencies

  • The compressed version is only 345 caracters long.
  • Faster than common libraries, even a large number of arrays, or on very big arrays. (See benchmarks)

Usage

@emrul
emrul / IOUtil.java
Created April 20, 2016 00:30 — forked from awilmore/IOUtil.java
Fast nio InputStream to OutputStream Copy
package com.awilmore.ioutils;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
@emrul
emrul / README.md
Created April 28, 2016 00:18 — forked from vjt/README.md
[POC] Temporal database system on PostgreSQL with Active Record in mind

This has become a Ruby gem: https://github.com/ifad/chronomodel

A temporal database system on PostgreSQL using table inheritance and the rule system.

This is a data structure for a Slowly-Changing Dimension Type 2 temporal database, implemented using only PostgreSQL >= 9.0 features.

Any application code is completely unaware of the temporal features: queries are done against a view that behaves exactly like a plain table (it can be SELECTed, UPDATEd, INSERTed INTO and DELETEd FROM), but behind the scenes the database redirects the queries to backend tables holding actual data, using the PostgreSQL rule system.

@emrul
emrul / tardis.sql
Created August 24, 2016 11:44 — forked from iperdomo/tardis.sql
-- psql -U postgres -h localhost -f /path/to/tardis.sql
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
@emrul
emrul / createJsonTypes.groovy
Created September 27, 2016 19:23
Create document types in CMIS from definitions stored in files in local filesystem using OpenCMIS Workbench scripting
import org.apache.chemistry.opencmis.commons.*
import org.apache.chemistry.opencmis.commons.data.*
import org.apache.chemistry.opencmis.commons.enums.*
import org.apache.chemistry.opencmis.commons.impl.*
import org.apache.chemistry.opencmis.client.api.*
import org.apache.chemistry.opencmis.commons.definitions.*
import org.apache.chemistry.opencmis.client.util.*
import static groovy.io.FileType.*
import static groovy.io.FileVisitResult.*
@emrul
emrul / dl4jRNNStockTimeSeriesRegressionExample.txt
Created January 22, 2017 15:30 — forked from ddrummond/dl4jRNNStockTimeSeriesRegressionExample.txt
DL4J Example of Time Series Regression with 2 Outputs:
/*
Problem Description:
Time series forecast for a single securities minor reversal points.
A "minor reversal point" is defined as either a period (day) with a high price greater than both the previous and next high prices, or a period with a low value lower than both the previous and next low prices.
This is a time series regression problem with 8 input features and 2 regression output dimensions
Input Features:
- period return r = (p2 - p1) / p1, descr: a linear return value, typically [-0.05,0.05]
- period volume, descr: standardized, z = (x - Mean) / SD
- High-Low spread, descr: standardized, z = (x - Mean) / SD
@emrul
emrul / Example.kt
Last active February 8, 2018 19:08
Hack to get Jsoniter to recognise JSONProperty annotations on Kotlin data classes
data class User(@JsonProperty("userName") val name: String)
val userObj = User("John")
JsoniterKotlinSupport.enable()
JsoniterAnnotationSupport.enable()
val jsonUserString = JsonStream.serialize(userObj)
// jsonUserString will contain: {"userName":"John"}
@emrul
emrul / enum.sql
Created February 9, 2018 10:41 — forked from d11wtq/enum.sql
Renaming an ENUM label in PostgreSQL
/*
Assuming you have an enum type like this.
You want to rename 'pending' to 'lodged'
*/
CREATE TYPE dispute_status AS ENUM('pending', 'resolved', 'open', 'cancelled');
BEGIN;
ALTER TYPE dispute_status ADD VALUE 'lodged';
UPDATE dispute SET status = 'lodged' WHERE status = 'pending';
@emrul
emrul / useful_pandas_snippets.py
Created March 18, 2018 10:29 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!