Skip to content

Instantly share code, notes, and snippets.

View afarber's full-sized avatar
🏠
Working from home

Alexander Farber afarber

🏠
Working from home
View GitHub Profile
@ledangtuanbk
ledangtuanbk / haproxy-redirect-base-on-payload
Last active February 21, 2022 17:39
Haproxy redirect request base on body
Based on this guide
https://stackoverflow.com/questions/23259843/how-to-route-traffic-reverse-proxy-with-haproxy-based-on-request-body
frontend http-in
bind *:80
option http-buffer-request
acl redirect_pingpong req.body -m reg [insert your regular expression here]
use_backend pingpong_backend if redirect_pingpong
default_backend web_bk
@ZsoltMedgyesi-Itineris
ZsoltMedgyesi-Itineris / wayid.lua
Created November 21, 2018 08:30
OSRM profile which gives wayIDs back as road names.
-- Car profile
api_version = 4
Set = require('lib/set')
Sequence = require('lib/sequence')
Handlers = require("lib/way_handlers")
Relations = require("lib/relations")
find_access_tag = require("lib/access").find_access_tag
limit = require("lib/maxspeed").limit
@dlew
dlew / script.sh
Created November 9, 2018 16:36
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@nanasess
nanasess / Jwks.cs
Created August 8, 2017 01:04
RSA public key to JWKs(JSON Web Key Set) for C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
namespace TestCommands
@Suleiman19
Suleiman19 / Header.java
Last active June 27, 2019 14:31
Sample code snippets for using mikepenz/FastAdapter library and its various features
public class Header extends AbstractItem<Header, Header.ViewHolder> {
String title;
public Header(String title) {
this.title = title;
}
public String getTitle() {
return title;
@bonnyfone
bonnyfone / gen_resconfig.sh
Last active January 8, 2018 10:13
Simple bash script which automatically generates locales resConfigs snippet from your project's res/ directory
#!/bin/bash
GREEN='\033[0;32m'
NC='\033[0m'
printf "Generating resConfig from resource dir: $1\n"
resconfig="resConfigs"
for values in `ls $1 | grep values-`; do
log="Inspecting $values"
if [ -f "$1/$values/strings.xml" ]
then
suffix=`echo $values | sed 's/values-//g'`
@puf
puf / ChatMessage.java
Last active July 12, 2021 21:56
Zero to App: Develop with Firebase (for Android - Google I/O 2016)
package com.google.firebase.zerotoapp;
public class ChatMessage {
public String name;
public String message;
public ChatMessage() {
}
public ChatMessage(String name, String message) {
@rohanag12
rohanag12 / SslUtil.java
Last active April 5, 2024 16:28
Create an SslSocketFactory using PEM encrypted certificate files
/**
* Utility class to read encrypted PEM files and generate a
* SSL Socket Factory based on the provided certificates.
* The original code is by Sharon Asher (link below). I have modified
* it to use a newer version of the BouncyCastle Library (v1.52)
*
* Reference - https://gist.github.com/sharonbn/4104301"
*/
import org.bouncycastle.cert.X509CertificateHolder;
@meineerde
meineerde / haproxy_1_5.cnf
Last active January 19, 2023 02:23
HAPROXY: Redirect all requests to a URL starting with /foo to /bar while retaining everything following it
# In HAProxy 1.5, we have to jump through some hops to accomplish a rewrite of a request's path...
# We use a temporary header to build our new path from the existing one in the request
# and then directly perform a redirect
# Clean the request and remove any existing header named X-Rewrite
http-request del-header X-REWRITE
# Copy the full request URL into the X-REWRITE request header unchanged
http-request add-header X-REWRITE %[url] if { path_beg /foo }