Skip to content

Instantly share code, notes, and snippets.

caike /
Created Nov 30, 2022
Addresses and Keys for Smart Contract demo
cardano-cli address key-gen --verification-key-file 02.vkey --signing-key-file 02.skey
cardano-cli address build \
--payment-verification-key-file 02.vkey \
--out-file 02.addr --testnet-magic 2
# Optional for debugging
## generates key files for staking address
cardano-cli stake-address key-gen \
--verification-key-file 01-stake.vkey \
--signing-key-file 01-stake.skey
caike /
Created Nov 10, 2022
asdf erlang elixir m1
export KERL_CONFIGURE_OPTIONS="--disable-hipe --with-ssl=$(brew --prefix openssl@1.1)"
asdf install erlang
caike /
Last active Oct 17, 2022
Node.js streams 1 vs. 2

NodeJS Streams

  • Current implementation is known as streams2.
  • Introduced in node v0.10.
  • "suck" streams instead of "spew" streams.
  • Instead of data events spewing, call read() to pull data from source.
  • When there isn't any data to consume, then read() will return undefined.
  • Adding a data event listener will switch the Readable stream into "old mode", where data is emitted as soon as it is available rather than waiting for you to call read() to consume it. This requires you to handle backpressure problems manually.
  • The pipe method helps write less code and handles back-pressure.
  • If you add an end listener and don't ever read() or pipe(), it'll never emit end.
caike /
Last active Oct 2, 2022
XSS attack demo with innerHTML

Tested with Chrome, Firefox and Safari.

The following code will not trigger an alert. target.innerHTML = "<script> alert('XSS Attack'); </script>";

The following code will trigger an alert. target.innerHTML = "";

caike /
Last active Aug 1, 2022
post about Node.js, non-blocking I/O and the event loop

#Node.js and the Event Loop

Node.js is a framework for writing server-side JavaScript applications. It is built on top of the V8 JavaScript runtime and uses an event-driven, non-blocking I/O model that makes it perfectly suited for data-intensive real-time applications.

This blog post will describe what non-blocking I/O means and how working with the event loop can help your applications be more efficient.

##The Restaurant

"This [non-blocking I/O] model simplifies access to slow resources in a scalable way that is intuitive to JavaScript programmers and easy to learn for everyone else." - Node Up and Running.

caike / import_from_wp.rake
Last active Jan 7, 2022
Basic script to parse WordPress XML. Although Nokogiri is the most popular lib for XML in Ruby these days, I've found Hpricot's API to be a lot easier to work with.
View import_from_wp.rake
desc 'import from WordPress XML file'
task :import_from_wp => :environment do
require 'hpricot'
doc = Hpricot::XML('wp-export-file.xml'))
posts = (doc/:channel/:item)
posts.each do |post|
p "Post: #{'link').inner_text}"
caike / a_smell.rb
Created Nov 28, 2012
Tell, Don't Ask.
View a_smell.rb
class SomeClass
def some_method(obj)
class SomeOtherClass
caike / error.rb
Created May 19, 2012
nested begin;rescue;end
View error.rb
class FooError < StandardError
p "about to raise Foo.."
rescue FooError
p 'rescues from Foo'
p 'about to raise Meh..'
caike / 01.Dockerfile
Last active Aug 10, 2021
Learn the differences between ENVs and ARGs in Docker
View 01.Dockerfile
FROM alpine:latest
# 01- ENV set directly in Dockerfile.
# Available during BUILDTIME and RUNTIME.
# 02 - ARG sent via command (docker or docker-compose)
# Available during BUILDTIME only.
caike / migration.exs
Last active Jul 5, 2021
snippets para o blog post sobre mix task
View migration.exs
defmodule GuitarStore.Repo.Migrations.AddIsCustomShopToGuitars do
use Ecto.Migration
def change do
alter table("guitars") do
add :is_custom_shop, :boolean, default: false
create index("guitars", ["is_custom_shop"])