Skip to content

Instantly share code, notes, and snippets.

View foeken's full-sized avatar

Andre Foeken foeken

  • Nedap
  • Groenlo, The Netherlands
View GitHub Profile
@foeken
foeken / chinese-fix.js
Created March 13, 2021 15:19
Fix Chinese page creation in Roam Research
// Fix broken page creation for Chinese
document.addEventListener('input', function(e){
var elem = e.target;
var pos = elem.selectionStart;
if (elem.nodeName != 'TEXTAREA' || e.data != '【') return;
elem.value = elem.value.replace('【','[]');
elem.setSelectionRange(pos, pos);
});
@foeken
foeken / encryptor.ex
Created September 13, 2018 08:45
ActiveSupport MessageEncryptor Elixir HMAC ExCrypto
defmodule ActiveSupportMessageEncryptor do
def encrypt(map, key) do
clear_text = Poison.encode!(map)
{:ok, aes_256_key} = Base.decode64(key)
{:ok, {iv, cipher_text}} = ExCrypto.encrypt(aes_256_key, clear_text)
payload = [cipher_text, iv] |> Enum.map(fn x -> Base.encode64(x) end) |> Enum.join("--") |> Base.encode64()
digest = :crypto.hmac(:sha, aes_256_key, payload) |> Base.encode16(case: :lower)
[payload, digest] |> Enum.join("--")
end
end

Multi tenant Elixir / Phoenix

I'm starting to use Elixir and Phoenix. I want to use a multi-tenant database setup like the Apartment gem provides for Rails apps.

The core setup is this:

  • Request comes in from specific subdomain
  • Translate subdomain to specific tenant database
  • Set the database to the tenant database
@foeken
foeken / content.js
Last active May 23, 2016 16:41
Crude Google Chrome Ninchanese extension
function getImageUrl(searchTerm, callback, errorCallback) {
var api_key = 'XXX'; // NOTE, the API is limited so you need a personal API key and Custom Search Engine ID
var cx_key = 'XXX'; // SEE: https://github.com/hubot-scripts/hubot-google-images/issues/29#issuecomment-188960728
var searchUrl = 'https://www.googleapis.com/customsearch/v1?q=' + encodeURIComponent(searchTerm) + '&cx='+ cx_key +'&safe=high&searchType=image&key=' + api_key
var x = new XMLHttpRequest();
x.open('GET', searchUrl);
x.responseType = 'json';
x.onload = function() {
@foeken
foeken / gist:f44e948bbc180fbdf3a5
Created March 13, 2016 16:15
font-color does not work
paragraph-divider {
font-color: $light-grey
margin-top: 12pt
margin-bottom: 12pt
text-alignment: center
content: "• • •"
}
@foeken
foeken / gist:018bbb5c1e482a9cf95b
Created September 30, 2014 16:38
A crude Github - Zendesk syncer
class Zendesk
ENDPOINT = "https://[DOMAIN].zendesk.com/api/v2"
USER = "[YOUR_USER_NAME]"
USER_ID = 0 #[YOUR_USER_ID]
TARGET_VIEW = 0 #[VIEW_ID]
BODY_FIELD_ID = 0 # [CUSTOM_BODY_FIELD_ID], We use an internal body
REPO_NAME_FIELD_ID = 0 #[REPO_NAME_FIELD_ID], We use a selectbox
GITHUB_FIELD_ID = 0 #[GITHUB_FIELD_ID], We use a checkbox
@foeken
foeken / gist:d4b4e207fda19abb9614
Created July 11, 2014 21:58
Get ING back to sanity
// Hack the 1password extention on OSX:
// Locate: /Users/[USERNAME]/Library/Application Support/Google/Chrome/Default/Extensions/aomjjhallfgjeglblehebfpbcfeobpgk
// Add this to global.min.js, look for var Ka = [{template},{template},{template}]
{
template_for: [/:\/\/mijn\.ing\.nl\//],
hints: [
["input[type=text]", "username"],
["input[type=password]", "password"]
@foeken
foeken / keybase.md
Created March 15, 2014 11:07
Keybase Proof

Keybase proof

I hereby claim:

  • I am foeken on github.
  • I am dreetje (https://keybase.io/dreetje) on keybase.
  • I have a public key whose fingerprint is 7DC5 D6AA 64D6 6CF1 FF9E 0686 65BB 0DBC E7CE 60FE

To claim this, I am signing this object:

@foeken
foeken / gist:4160705
Created November 28, 2012 11:54
RubyMotion Bug in Module ordering
# Take the following setup, this works if everything is inside a single file.
# app/foo/monkey.rb
module Foo
module Monkey
puts "Monkey"
end
end
# app/foo/nut.rb
@foeken
foeken / gist:3739301
Created September 17, 2012 19:35
Javascript tests :)
Feature: Adaptive layout functionality
As a registered user
In order to productive on a range of devices
I want Caren Pro to fluidly scale the amount of information displayed
Background:
Given a care provider "Care4All"
And a "Care4All" employee "Andre"
And "Andre" has an activated account
And "Andre" is logged in