Skip to content

Instantly share code, notes, and snippets.

/* import Tika into a file with this */
import org.apache.tika.Tika;
/*
assume the file's content is in a string called 'file'
you can detect a file's mime type with the following
https://tika.apache.org/1.8/api/org/apache/tika/Tika.html#detect(byte[])
*/
String detectedFileType = (new Tika()).detect(file.getBytes())
@efossas
efossas / papaparse.js
Created May 13, 2018 22:48
papaparse.js
// get csvStr, and pass it to .parse
let csv = Papa.parse(csvStr,{
transform: function (value) {
try {
return JSON.parse(value);
} catch(err) {
return value;
}
}
});
@efossas
efossas / tampermonkey.js
Created May 19, 2018 03:05
tampermonkey-hulu-play-pause
// ==UserScript==
// @name Hulu Play/Pause
// @namespace http://abaganon.com/
// @version 0.1
// @description Add play/pause shorcut to Hulu
// @author Eric Fossas
// @match https://www.hulu.com/watch/*
// @grant none
// ==/UserScript==
@efossas
efossas / css.js
Created May 26, 2018 17:25
css.js
/* import all 3 libraries and file system for writing the final file */
var sass = require('node-sass');
var CleanCSS = require('clean-css');
var uncss = require('uncss');
var fs = require('fs');
/* compile scss files */
// you need to set 'filename' to a string of the path to your main scss file
sass.render({file: filename}, function(err, result) {
if (err) {
@efossas
efossas / serialize.js
Last active August 4, 2018 18:14
serialize.js
/*
value - the variable to serialize
LIMIT - (optional) number of chars to limit nested variables to, obviously breaks deserialize
*/
function serialize(value,LIMIT) {
switch(typeof value) {
case "function":
var func = value.toString();
if (func.search(/\[[^,'"`]+\]/g) > -1) {
var ROOT;
@efossas
efossas / Dockerfile
Last active August 19, 2018 16:55
Dockerfile
# the FROM instruction sets the original image to start with
# namespace/image:tag
# without a namespace, the image is must be an official docker image. https://docs.docker.com/docker-hub/official_repos/
# without a tag, 'latest' is the default
# so here, we'll use a container with node installed on it, using the Alpine OS, which is very lightweight
FROM node:alpine
# the RUN instruction runs a command
# here we use the apk package manager to install git and other tools
RUN apk update && apk upgrade && apk add coreutils git openssl wget
@efossas
efossas / docker-compose.yml
Last active August 19, 2018 19:22
docker-compose.yml
# set the version of Docker compose to use
# avoiding the minor number just uses the latest version, i.e. 3 -> 3.7
version: '3'
# our Docker networks. we create just one: 'proxy'
# we set 'proxy' to use the 'bridge' driver, which actually happens by default if that field is omitted
# since our containers aren't on the 'host' network, they will be isolated from the host until we do some port mapping/exposing
# if you don't define a network, docker compose will create a 'default' network and put all services/containers on it
networks:
proxy:
@efossas
efossas / .env
Last active August 19, 2018 19:24
.env
# environment variables that start with 'COMPOSE' or 'DOCKER' are for setting docker configuration
# https://docs.docker.com/compose/reference/envvars/
# compose uses a project namespace for a 'stack', a collection of services orchestrated by a docker-compose.yml file
COMPOSE_PROJECT_NAME=crud
# you can set one or multiple compose files (separated by a ':') to use when running docker-compose up
COMPOSE_FILE=docker-compose.yml
# you can also add environment variables that can be be used in docker-compose.yml files
@efossas
efossas / traefik.toml
Created August 19, 2018 19:57
traefik.toml
# enable logging on the debug level
logLevel = "DEBUG"
# log Traefik related stuff. It defaults to logging to stdout
# to view logs, run the command: docker logs traefik
[traefikLog]
# log requests. It defaults to logging to stdout
# the filters are for logging only requests that get certain http status codes, in this case we log everything
[accessLog]
@efossas
efossas / app.module.ts
Created August 23, 2018 14:28
app.module.ts
import { NgModule } from '@angular/core';
import { StoreModule } from '@ngrx/store';
@NgModule({
imports: [StoreModule.forRoot({})]
})
export class AppModule {}