Skip to content

Instantly share code, notes, and snippets.

View barkerja's full-sized avatar
🤷‍♂️
🤷🏻

John Barker barkerja

🤷‍♂️
🤷🏻
  • Dryden, NY
View GitHub Profile
@barkerja
barkerja / component_under_test.ex
Created February 26, 2024 13:20 — forked from mcrumm/component_under_test.ex
Testing Phoenix.LiveComponent in Isolation
# lib/party_web/components/example_component.ex
defmodule PartyWeb.ExampleComponent do
@moduledoc """
An example LiveComponent under test.
"""
use Phoenix.LiveComponent
def render(assigns) do
~H"""
<div>
@barkerja
barkerja / AesUtil.ts
Created February 20, 2024 22:44 — forked from btxtiger/AesUtil.ts
Node.js - AES Encryption/Decryption with AES-256-GCM using random Initialization Vector + Salt
/**
* Cryptography Functions
*
* Forked from AndiDittrich/AesUtil.js
* https://gist.github.com/AndiDittrich/4629e7db04819244e843
*/
import crypto, { CipherGCM, CipherGCMTypes, DecipherGCM } from 'crypto';
import { Password } from './types';
@barkerja
barkerja / new_in_kino_bumblebee_0_1_3.livemd
Created February 25, 2023 03:41 — forked from hugobarauna/new_in_kino_bumblebee_0_1_3.livemd
This notebook showcases two new neural network tasks added to Livebook Kino Bumblebee v0.1.3

What's new in Kino Bumblebee v0.1.3

Mix.install(
  [
    {:kino_bumblebee, "~> 0.1.3"},
    {:exla, "~> 0.4.1"}
  ],
  config: [nx: [default_backend: EXLA.Backend]]
)
@barkerja
barkerja / snowflake-id.sql
Created March 4, 2020 21:31 — forked from beginor/snowflake-id.sql
Twitter Snowflake ID for PostgreSQL
CREATE SEQUENCE public.global_id_seq;
ALTER SEQUENCE public.global_id_seq OWNER TO postgres;
CREATE OR REPLACE FUNCTION public.id_generator()
RETURNS bigint
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
our_epoch bigint := 1314220021721;
seq_id bigint;
@barkerja
barkerja / latency.txt
Created April 9, 2018 04:37 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@barkerja
barkerja / About.md
Created March 13, 2017 03:56 — forked from melicarls/About.md
React.js Lightning Talk

React.js

What is React.js?

React is a "declarative, efficient, and flexible Javascript library for building user interfaces." It was created by Facebook, first deployed in 2011, and was open-sourced in 2013. It is one of many answers to everyone's favorite question: "how should we structure Javascript applications on the web?"

Goal:

Minimize the amount of mutation that developers have to deal with by totally redoing the view every time that the data on a page changes. The developer writes the code for the page's first load but never has to account for modifications since every change to the page is treated like that initial render!

@barkerja
barkerja / the-bind-problem.jsx
Created November 28, 2016 20:19 — forked from Restuta/the-bind-problem.jsx
React, removeEventListener and bind(this) gotcha
/* Sometimes it's pretty easy to run ito troubles with React ES6 components.
Consider the following code: */
class EventStub extends Component {
componentDidMount() {
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind
}
componentWillUnmount() {
window.removeEventListener('resize', this.onResize.bind(this));
@barkerja
barkerja / nginx.conf
Created February 13, 2016 18:18 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@barkerja
barkerja / GIF-Screencast-OSX.md
Last active September 12, 2015 23:26 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@barkerja
barkerja / db.rake
Last active August 29, 2015 14:14 — forked from tehpeh/db.rake
namespace :db do
namespace :enable do
desc "enable hstore extension"
task :hstore => [:environment, :load_config] do
ActiveRecord::Base.connection.execute('CREATE EXTENSION IF NOT EXISTS hstore;')
end
end
Rake::Task['db:schema:load'].enhance ['db:enable:hstore']
end