Skip to content

Instantly share code, notes, and snippets.

View coderdan's full-sized avatar

Dan Draper coderdan

View GitHub Profile
@coderdan
coderdan / fake_using.rb
Created April 3, 2023 04:20
Example of using encrypted values as deterministic seeds for Faker
require 'rubygems'
require 'faker'
def fake_using(hex_str)
prev_random = Faker::Config.random
Faker::Config.random = Random.new(hex_str.to_i(16))
result = yield
Faker::Config.random = prev_random
result
end
@coderdan
coderdan / yaml
Created February 16, 2023 00:27
Demo config
tables:
- path: users
fields:
- name: name
in_place: false
cast_type: utf8-str
mode: encrypted-duplicate
indexes:
- version: 1
kind: match
import { HasID, QueryResult, Stash } from "@cipherstash/stashjs"
import { movieSchema, Movie } from "./example-schema";
function displayResults(result: QueryResult<Movie & HasID>, name: string) {
result.documents.forEach((movie: Movie) => {
console.log(movie)
})
// TODO: print count
console.log("--------------------------------------------------")
console.log(name)
CREATE TYPE ore_block_64_8;
CREATE FUNCTION ore_block_in_64_8(cstring)
RETURNS ore_block_64_8
AS '$libdir/pgsecret'
LANGUAGE C IMMUTABLE STRICT;
CREATE FUNCTION ore_block_out_64_8(ore_block_64_8)
RETURNS cstring
AS '$libdir/pgsecret'
["Crocodile", "Giraffe", "Lion", "Tiger"]
|> Enum.map(&String.capitalize/1)
|> Enum.sort
["Crocodile", "Giraffe", "Lion", "Tiger"].map { |word|
word.capitalize
}.sort
def print_name(%User{firstname: fname, lastname: lname}) do
"#{fname} #{lname}"
end
def print_name(%User{} = user) do
"#{user.firstname} #{user.lastname}"
end
def print_name(_) do
"Unknown"
end
def print_name(user)
if user.present? and user.kind_of?(User)
"#{user.firstname} #{user.lastname}"
else
"Unknown"
end
end
@coderdan
coderdan / resolver.ex
Last active April 18, 2018 07:45
Edge resolution with dataloader
import Absinthe.Resolution.Helpers
connection field :contracts, node_type: :contract do
resolve fn %{id: project_id}, args, %{context: %{current_user: current_user}, dataloader: loader} ->
loader
|> Dataloader.load_many(Engagement, :contract_ids_for_project_id, project_id)
|> on_load(fn loader ->
{
:ok,
Connection.from_list(