Skip to content

Instantly share code, notes, and snippets.

View kwando's full-sized avatar
🦀

Hannes Nevalainen kwando

🦀
View GitHub Profile
@kwando
kwando / ecto_schema.livemd
Created September 14, 2022 09:00
Ecto param schemas [livebook]

Ecto Schema

Mix.install([:ecto])

Section

defmodule ParamSchema do
@kwando
kwando / param_schema.ex
Created October 25, 2020 09:03
ParamSchema
defmodule ParamSchema do
defmodule ValidationHelpers do
def validate_subset1(changeset, key, values) do
Ecto.Changeset.get_field(changeset, key)
|> case do
nil -> changeset
selected_values ->
Enum.split_with(selected_values, &Enum.member?(values, &1))
|> IO.inspect(label: "hello")
@kwando
kwando / certcheck.rb
Created January 29, 2020 14:50
Check certificate expiration
#!/usr/bin/env ruby
require 'date'
require 'time'
domain = ARGV[0]
if !domain
STDERR.puts "no domain given"
exit(-1)
end
@kwando
kwando / repo.rb
Created February 13, 2017 14:34
Custom read type ruby repo
require 'bundler'
Bundler.setup
require 'sequel'
DB = Sequel.connect('sqlite::memory')
DB.create_table(:users) do
primary_key(:id)
String :name, null: false
require 'bundler'
Bundler.setup
require 'sequel'
DB = Sequel.connect('sqlite::memory')
DB.create_table(:users) do
primary_key(:id)
String :name, null: false
@kwando
kwando / schema.rb
Last active April 19, 2016 08:07
Schema support for your adapter
require 'dry/types'
module ROM
module Plugins
module Relation
module Schema
Undefined = Object.new.freeze
def self.included(klass)
super
@kwando
kwando / jruby 9.0.4.0
Created January 12, 2016 12:43
dry-v benchmarks
user system total real
DV: 1 thread 0.830000 0.020000 0.850000 ( 0.761257)
AM: 1 thread 5.880000 0.160000 6.040000 ( 5.992480)
DV: 2 threads 0.750000 0.010000 0.760000 ( 0.374995)
AM: 2 threads 5.370000 0.080000 5.450000 ( 2.780504)
Calculating -------------------------------------
DV: 1 thread 1.000 i/100ms
AM: 1 thread 1.000 i/100ms
@kwando
kwando / gist:0f75729ece0fe4e20c14
Created May 29, 2015 07:46
Virtus + AM::Validations
class ApprovalsController < ApplicationController
def index
query = ApprovalQuery.new(params)
return render(json: {errors: query.errors.full_messages}, status: 422) unless query.valid?
render json: Approval.apply_query(query)
end
end
class ApprovalQuery < Query::Base
/**
* Retrieve the posts based on query variables.
*
* There are a few filters and actions that can be used to modify the post
* database query.
*
* @since 1.5.0
* @access public
* @uses do_action_ref_array() Calls 'pre_get_posts' hook before retrieving posts.
*
java -jar TreeEditor.jar
maj 03, 2014 10:07:42 EM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.x
maj 03, 2014 10:07:42 EM com.jme3.system.Natives extractNativeLibs
INFO: Extraction Directory: /Users/kwando/Downloads/TreeEditor-2.app/Contents/Java
maj 03, 2014 10:07:42 EM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Lwjgl 2.9.0 context running on thread LWJGL Renderer Thread
maj 03, 2014 10:07:42 EM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: null
maj 03, 2014 10:07:42 EM com.jme3.system.lwjgl.LwjglContext printContextInitInfo