Skip to content

Instantly share code, notes, and snippets.

@Thomas-P
Thomas-P / service-worker.d.ts
Created July 4, 2018 13:17 — forked from ithinkihaveacat/service-worker.d.ts
Typings for using the Service Worker API with TypeScript
/**
* Copyright (c) 2016, Tiernan Cridland
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
* granted, provided that the above copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
@Thomas-P
Thomas-P / persistence.xml
Created January 9, 2018 15:39 — forked from mortezaadi/persistence.xml
persistence xml configurations for major databases and jpa providers
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<!-- derby -->
@Thomas-P
Thomas-P / rxjs_operators_by_example.md
Created December 3, 2017 11:11 — forked from btroncone/rxjs_operators_by_example.md
RxJS 5 Operators By Example
@Thomas-P
Thomas-P / Flatten.cs
Created August 20, 2017 23:05
How to flat an array into Unity Game Engine with C#.
public static class Flatten {
public static T[] Flat<T>(T[,] toFlat)
{
int width = toFlat.GetLength(0);
int height = toFlat.GetLength(1);
int size = width * height;
T[] result = new T[size];
for (int i=0;i<size; i++)
{
@Thomas-P
Thomas-P / HttpDigestAuth.java
Created July 7, 2017 18:40 — forked from slightfoot/HttpDigestAuth.java
HTTP Digest Auth for Android (incomplete and probably hackable, but works!)
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
@Thomas-P
Thomas-P / MainActivity.java
Last active July 5, 2017 08:13
Blueprint for request contact infos on android with the request permission runtime api
import android.Manifest;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.LoaderManager;
@Thomas-P
Thomas-P / parse-csv.ts
Last active April 29, 2017 11:39
Split a row of an CSV file with quotes.
/**
* parse a chunked csv file and give the result per row back if it is finished
* @param withHeader
* @param delimiter
* @param quotes
* @returns {(chunk:string, callback:(result:(Array<string>|Object))=>void)=>void}
*/
function parseCSV(withHeader: boolean, delimiter: string = ';', quotes: string = '"') {
let tmpString = '';
let headerCells: Array<string> = null;
@Thomas-P
Thomas-P / JsonLoader.java
Created March 5, 2017 19:46 — forked from OleksandrKucherenko/JsonLoader.java
Volley Library adaptation for Loader pattern.
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.Loader;
import com.android.volley.NoConnectionError;
import com.android.volley.Response;
import com.android.volley.RetryPolicy;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonRequest;
@Thomas-P
Thomas-P / upsert.sql
Created March 1, 2017 15:37 — forked from shihpeng/upsert.sql
Upsert in SQLite
-- Reference: http://stackoverflow.com/questions/418898/sqlite-upsert-not-insert-or-replace
-- Approach #1: Select original values before insertion.
-- demo table 'emplyee'
CREATE TABLE employee (
id INTEGER PRIMARY KEY,
role TEXT,
name TEXT);
-- This will update 2 of the columns. When ID=1 exists, the NAME will be unaffected. When ID=1 does not exist, the name will be default (NULL).
@Thomas-P
Thomas-P / softmax.ts
Created December 4, 2016 15:49
Softmax algorithm for one or two dimensional arrays
const sumMethod = (a, b) => a + b;
const transpose = m => m[0].map((x, i) => m.map(x => x[i]));
/**
* Softmax for one or two dimensional arrays
*/
export const softmax = (arr: [number | [number]]) => {
if (arr.every(item => Array.isArray(item))) {
return transpose(transpose(arr).map(item => softmax(<[number]>item)));
} else {
const sumRow = arr.map(value => Math.exp(<number>value)).reduce(sumMethod);