Skip to content

Instantly share code, notes, and snippets.

@xhh
xhh / exwx.exs
Last active June 21, 2022 09:59 — forked from rlipscombe/exwx.exs
Using wxWidgets from Elixir
#!/usr/bin/env elixir
defmodule Canvas do
@behaviour :wx_object
@title "Canvas Example"
@size {600, 600}
def start_link() do
:wx_object.start_link(__MODULE__, [], [])
@xhh
xhh / wx.ex
Created June 8, 2022 14:09 — forked from dominicletz/wx.ex
wx.ex
defmodule Wx do
@vsn "0.0.2"
@author "Onorio Catenacci"
@author "Dominic Letz"
@last_revision_date "22 May 2019"
@moduledoc """
Elixir version of the constants found in the wx.hrl file
"""
import Bitwise
require Record
@xhh
xhh / main.exs
Created April 14, 2022 15:05
groups maps by common keys
list = [
%{id: 1, k: "k1", name: "name a", text: "text a"},
%{id: 1, k: "k1", name: "name b", other: "other b"},
%{id: 1, k: "k2", name: "name k2", other: "other k2"}
]
keys = [:id, :k]
list
|> Enum.group_by(&Map.take(&1, keys))
@xhh
xhh / AddPostgresTriggerAndFunctionForAllTables.exs
Created July 8, 2021 09:32 — forked from carterbryden/AddPostgresTriggerAndFunctionForAllTables.exs
Elixir Phoenix Postgresql migration to add triggers for pubsub to run on every CRUD operation on every table. If a new table is added, it'll automatically add a trigger to that table too.
defmodule MyApp.Repo.Migrations.AddPostgresTriggerAndFunctionForAllTables do
use Ecto.Migration
def up do
# Create a function that broadcasts row changes
execute "
CREATE OR REPLACE FUNCTION broadcast_changes()
RETURNS trigger AS $$
DECLARE
current_row RECORD;

JSON 递归处理

数据

json = """
[
  {
    "k1": "v1",
    "k2": {
@xhh
xhh / ssl.rules
Created March 31, 2021 14:04 — forked from konklone/ssl.rules
nginx TLS / SSL configuration options for konklone.com
# Basically the nginx configuration I use at konklone.com.
# I check it using https://www.ssllabs.com/ssltest/analyze.html?d=konklone.com
#
# To provide feedback, please tweet at @konklone or email eric@konklone.com.
# Comments on gists don't notify the author.
#
# Thanks to WubTheCaptain (https://wubthecaptain.eu) for his help and ciphersuites.
# Thanks to Ilya Grigorik (https://www.igvita.com) for constant inspiration.
server {
@xhh
xhh / openpgp.md
Last active December 29, 2020 07:10
@xhh
xhh / clojure_misc.clj
Last active March 1, 2020 13:07
some clojure code
(defmacro comp*
"The left-to-right version of comp.
Takes a set of functions and returns a fn that is the composition
of those fns. The returned fn takes a variable number of args,
applies the leftmost of fns to the args, the next
fn (left-to-right) to the result, etc."
[& fns]
`(comp ~@(reverse fns)))
@xhh
xhh / errocodeNX.md
Created March 11, 2017 03:01 — forked from dietmarkuehl/errocodeNX.md
error_code article

Defining and Using a Symbol Analogue for Error Reporting in C++

Abstract

The use of exceptions isn't a viable error handling approach in all cases and returning codes for error handling is sometimes preferable. However, using integral types for error identification is problematic as there is no good mechanism to guarantee that each value uniquely

@xhh
xhh / keybase.md
Created September 23, 2015 08:17

Keybase proof

I hereby claim:

  • I am xhh on github.
  • I am xhh (https://keybase.io/xhh) on keybase.
  • I have a public key whose fingerprint is DA39 792E 3E51 743A 5BCA 49E1 F703 4D9F 9D65 BD6E

To claim this, I am signing this object: