Skip to content

Instantly share code, notes, and snippets.

View linuskohl's full-sized avatar
🙏

Linus Kohl linuskohl

🙏
View GitHub Profile
@linuskohl
linuskohl / CustomSerializer.php
Created August 20, 2018 20:21
Custom Yii2 serializer that allows masking and setting default fields and expands
<?php
namespace app\components;
use yii\base\InvalidConfigException;
/**
* Class CustomSerializer
*
* Serializer

Keybase proof

I hereby claim:

  • I am linuskohl on github.
  • I am linuskohl (https://keybase.io/linuskohl) on keybase.
  • I have a public key ASBe5pRAYVrsgPvHl3Qyi0M8NSLVuPfTOXX0tHtO-d_WpQo

To claim this, I am signing this object:

@linuskohl
linuskohl / tracking.js
Created January 24, 2019 15:26
Insights Cookie Consent Google Analytics Opt-Out Solution
var gaProperty = 'UA-XXXXXXXX-X';
// Get the name of the GA tracking disable cookie
var disableStr = 'ga-disable-' + gaProperty;
// Check if GA cookie exists
window[disableStr] = (document.cookie.indexOf(disableStr + '=true') > -1)
// Opt-out function
function gaOptout() {
@linuskohl
linuskohl / lee_mykland_jumps.py
Created April 8, 2019 08:15
Python Implementation of the Jump Detection Algorithm as described in the Paper "Jumps in Equilibrium Prices and Market Microstructure Noise" by Suzanne S. Lee and Per A. Mykland
from math import ceil, sqrt
import numpy as np
import pandas as pd
def movmean(v, kb, kf):
"""
Computes the mean with a window of length kb+kf+1 that includes the element
in the current position, kb elements backward, and kf elements forward.
Nonexisting elements at the edges get substituted with NaN.
@linuskohl
linuskohl / ambiverseclient-sample.py
Last active June 4, 2019 15:04
Sample code for medium article
# import client and input model
from ambiverseclient.clients import AmbiverseNLU, KnowledgeGraph
from ambiverseclient.models import AnalyzeInput
# specify the API endpoints
a_endpoint = AmbiverseNLU_ENDPOINT
kg_endpoint = KnowledgeGraph_ENDPOINT
# setup the clients
a_client = AmbiverseNLU(a_endpoint, port=8080)
@linuskohl
linuskohl / naive-benchmark-on-news-headlines.py
Created June 4, 2019 16:19
Naive benchmark of AmbiverseNLU on news headlines
# pip install newsapi-python
import time
import pandas as pd
import numpy as np
import seaborn as sns
from newsapi import NewsApiClient
newsapi = NewsApiClient(api_key=API_KEY)
# get 100 latest news items
top_news = newsapi.get_top_headlines(language='en', page_size=100)
@linuskohl
linuskohl / .gitlab-ci.yml
Created August 18, 2019 13:26
GitLab CI/CD for deploying a React app to an AWS S3 bucket
# GitLab CI/CD Variables
# AWS_S3_BUCKET_PROD: S3 bucket that hosts production files
# AWS_S3_BUCKET_DEV: S3 bucket that hosts development files
# AWS_ACCESS_KEY_ID: AWS Key ID
# AWS_SECRET_ACCESS_KEY: AWS Secret
stages:
- build
- deploy
@linuskohl
linuskohl / hsozkult.py
Created August 20, 2019 16:01
Tiny script to send notification emails on new openings on H-Soz-Kult
#!/usr/bin/env python
# coding: utf-8
import os
import feedparser
import requests
import sqlite3
from sqlite3 import IntegrityError
from lxml import html
import lxml
from string import Template
@linuskohl
linuskohl / jwt_helpers.py
Last active December 30, 2022 10:10
Helper functions to validate JSON Web Tokens for flask RESTful APIs by fetching JWKs from OpenID Provider Metadata. Used with Okta.
from functools import wraps
from flask import request, abort, g
import json
import jwt
import requests
from typing import Union, List
from ..config import cache
from ..env import JWT_ISSUER, JWT_CLIENTID, JWT_AUDIENCE
DISCOVERY_URL = "/.well-known/oauth-authorization-server"
@linuskohl
linuskohl / extract_links.js
Created April 9, 2020 09:30
Extract list of links by class in jQuery