Skip to content

Instantly share code, notes, and snippets.

View Big-al's full-sized avatar
🧨
If you think good architecture is expensive, try bad architecture.

Alan Kristensen Big-al

🧨
If you think good architecture is expensive, try bad architecture.
View GitHub Profile
@Big-al
Big-al / ingest_pdf_to_elk.py
Created May 22, 2023 16:14
Python script to ingest PDFs and other text document types to Elasticsearch in a simple schema, page by page.
import datetime
import json
import os
from pathlib import Path
from elasticsearch import Elasticsearch
from PyPDF2 import PdfReader
from ebooklib import epub
import mammoth
# ====================== Settings ======================
@Big-al
Big-al / get_distances_between_locations_with_google_maps.py
Last active December 15, 2021 21:23
Needed to get the distance between a few thousands of people and their workplace for an assignment. Turned out there was a number of overlaps, so this solution makes a naive improvement on a linear approach by using some simple memoization. Use this example as a helper on how the google maps location matrix api and csv file handling works in pyt…
import csv
from os import pathconf
import googlemaps # pip3 install googlemaps
print('Exepcting data in the following format (order is important):')
print('Some ID,Country of location 1,Zipcode of location 1,Zipcode of location 2;Country of location 2,distance')
print('Example line:')
print('id_log4j2,Denmark,8200,8250,Denmark, ')
api_key = input("Enter google maps api-key:")
@Big-al
Big-al / alias_notes.yaml
Created August 20, 2021 19:04
Default Alias. Updated whenever I have gotten tired of making a spelling mistake..
# Idiot alias
alias sl=ls \
alias æs=ls \
alias grpe=grep \
alias gerp=grep \
alias gti='/usr/local/bin/git' \
# Smart alias
alias l="tree --dirsfirst -ChFL 1" \
@Big-al
Big-al / kibana.yml
Created March 13, 2021 23:00
Kibana config for custom mapserver
## Maps
# Custom map server, as we are in an airgapped env with no access to elastic maps.
map.includeElasticMapsService: false
map.tilemap.url: "https://some.ip.address:3650/data/tileserver/{z}/{x}/{y}.jpg"
map.proxyElasticMapsServiceInMaps: false
# Set default max zoom level up to 24. Depends on quality of map. Lowress map used here is legible to about 7.
map.tilemap.options.maxZoom: 18
# OpenMapTiles license requires attribution.
#map.tilemap.options.attributions: "[OpenMapTiles](http://www.openmaptiles.org/)"
@Big-al
Big-al / tileserver.yaml
Last active March 13, 2021 23:25
Nginx config for vhost with SSL cert.
server {
listen 3650; # Port the site will be public on
server_name some.ip.address; # Change to your servers ip or dns address
# SSL Cert settings
ssl_certificate /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
ssl on;
@Big-al
Big-al / UnboundedKnapsackSolvers.cs
Created September 26, 2020 23:46
Unbounded minimum and maximum knapsack solver in c#
namespace UnboundedKnapsackSolvers
{
public class DriverProgram
{
// Driver program
public static void Main()
{
// Premise: We must use the entire Total Quantity.
int TQty = 36; // total quantity of the item
@Big-al
Big-al / Browser.ts
Created August 18, 2020 23:14
Example on how to create a puppeteer browser instance using a singleton pattern in Typescript, with error handling and performance optimizations.
Import puppeteer from 'puppeteer';
Import { LoggingService, LogLevel } from './LoggingService';
const Logger: LoggingService = LoggingService.getInstance();
export class Browser implements IBrowser {
private browser: puppeteer.Browser;
private readonly TIMEOUT: number;
private readonly USER_AGENT = 'INSERT_USERAGENT';
constructor(_timeout: number = 30000) {
@Big-al
Big-al / mongodb_c#_cheatsheet.md
Created April 13, 2020 18:37 — forked from a3dho3yn/mongodb_c#_cheatsheet.md
MongoDB C# Driver Cheat Sheet

MongoDB C# Driver Cheat Sheet

(C) 2015 by Derek Hunziker, (C) 2017 by AppsOn

As of releasing MongoDB 3.4 and C# Driver v2.4, original cheatsheet by Derek is outdated. In addition, it has some deficiencies like connecting to MongoDB, creating indexes, etc. This updated version works fine with C# Driver v2.4.7 and MongoDB v3.4.

Setup

Define Document Models

Note: Defined models and collections will be used in entire cheatsheet.

@Big-al
Big-al / StoredProcedureToList_Worker.cs
Last active September 6, 2019 13:14
Takes the name of a stored procedure, the type of list you wish to have returned and a list of sqlParameters. Returns a list mapped to the given type instead of for example a simple datatable.
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace API.Helpers
{
public class SQLHelpers
{
@Big-al
Big-al / gist:8ba3258025ecd84725a2020eaf3232b7
Created December 23, 2017 17:50
Error produced by docker build with Meteor image by jshimko on todos-master app by Meteor
C:\Users\Alanm\Desktop\testapp>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
C:\Users\Alanm\Desktop\testapp>docker build -t alantest .
Sending build context to Docker daemon 663.6kB
Step 1/1 : FROM jshimko/meteor-launchpad:latest
# Executing 17 build triggers...
Step 1/1 : ARG APT_GET_INSTALL
---> Using cache
Step 1/1 : ENV APT_GET_INSTALL $APT_GET_INSTALL