Skip to content

Instantly share code, notes, and snippets.

@cblavier
cblavier / app.js
Created January 9, 2021 10:55
Responsive Phoenix LiveView
const Hooks = { ViewportResizeHooks}
const connectLiveSocket = () => {
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute('content')
const liveSocket = new LiveSocket('/my_app/live', Socket, {
params: {
_csrf_token: csrfToken,
viewport: {
width: window.innerWidth,
height: window.innerHeight
--[=[
Relevant functions for creating lenses
Note that not all functions are always implemented
For Lens s t a b:
over : (a -> b) -> s -> t
Map a function over the target of the lens
Ex. over(each..each, function(x) return x+1 end, {{1,2},{3,4}})
@micimize
micimize / fab_remote_user.py
Created August 17, 2019 14:13
Full proxy control over flask app builder (and thus apache superset) authentication
from flask import Blueprint, redirect
from flask_login import current_user, logout_user
from flask_appbuilder.security.manager import AUTH_OAUTH, AUTH_REMOTE_USER
my_blueprint = Blueprint("My Blueprint", __name__)
@my_blueprint.before_app_request
def ensure_logout_correctness():
"""Ensure users are logged out when the proxy logs out
@bgentry
bgentry / access_instrumentation.rb
Last active August 9, 2019 10:57
graphql-ruby Pundit-based access control instrumentation
class FieldAccessInstrumentation
attr_reader :current_user_key
def initialize(current_user_key = :current_user)
@current_user_key = current_user_key
end
def instrument(type, field)
field = instrument_type(type, field) if type.metadata[:access]
# only add the field access check if it exists and isn't identical to the
defmodule CatcastsWeb.AuthControllerTest do
use CatcastsWeb.ConnCase
alias Catcasts.Repo # add this line
alias Catcasts.User # add this line
@ueberauth_auth %{credentials: %{token: "fdsnoafhnoofh08h38h"},
info: %{email: "batman@example.com", first_name: "Bruce", last_name: "Wayne"},
provider: :google}
... # Code removed for readability
@theorygeek
theorygeek / association_loader.rb
Last active October 31, 2023 07:15
Preloading Associations with graphql-batch
# frozen_string_literal: true
class AssociationLoader < GraphQL::Batch::Loader
attr_reader :klass, :association
def initialize(klass, association)
raise ArgumentError, "association to load must be a symbol (got #{association.inspect})" unless association.is_a?(Symbol)
raise ArgumentError, "cannot load associations for class #{klass.name}" unless klass < ActiveRecord::Base
raise TypeError, "association #{association} does not exist on #{klass.name}" unless klass.reflect_on_association(association)
@klass = klass
@kaspergrubbe
kaspergrubbe / geonames_postgres.rb
Last active April 4, 2024 08:12
Import files from Geonames.com into a PostgreSQL database that runs Postgis
#!/usr/bin/env ruby
require 'open3'
require 'fileutils'
def run_command(command)
puts("+: " + command)
Open3.popen2e(command) do |stdin, stdout_stderr, wait_thread|
Thread.new do
stdout_stderr.each {|l| puts l }
@max-mapper
max-mapper / index.sh
Last active November 2, 2023 10:13
generate ES512 and RS256 elliptic curve keypairs for JWT JWK (JSON Web Token JSON Web Key) using openssl
# RS256
# private key
openssl genrsa -out rs256-4096-private.rsa 4096
# public key
openssl rsa -in rs256-4096-private.rsa -pubout > rs256-4096-public.pem
# ES512
# private key
openssl ecparam -genkey -name secp521r1 -noout -out ecdsa-p521-private.pem
# public key
@jgrodziski
jgrodziski / docker-aliases.sh
Last active June 19, 2024 07:01
Useful Docker Aliases
############################################################################
# #
# ------- Useful Docker Aliases -------- #
# #
# # Installation : #
# copy/paste these lines into your .bashrc or .zshrc file or just #
# type the following in your current shell to try it out: #
# wget -O - https://gist.githubusercontent.com/jgrodziski/9ed4a17709baad10dbcd4530b60dfcbb/raw/d84ef1741c59e7ab07fb055a70df1830584c6c18/docker-aliases.sh | bash
# #
# # Usage: #
@slashdotdash
slashdotdash / create_projection_versions.ex
Last active June 5, 2023 12:46
Building projections with Ecto using Commanded event handlers
defmodule Projections.Repo.Migrations.CreateProjectionVersions do
use Ecto.Migration
def change do
create table(:projection_versions, primary_key: false) do
add :projection_name, :text, primary_key: true
add :last_seen_event_id, :bigint
timestamps
end