Skip to content

Instantly share code, notes, and snippets.

@caike
caike / node.md
Last active August 1, 2022 03:57
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
caike / import_from_wp.rake
Last active January 7, 2022 14:49
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.
desc 'import from WordPress XML file'
task :import_from_wp => :environment do
require 'hpricot'
doc = Hpricot::XML(File.read('wp-export-file.xml'))
posts = (doc/:channel/:item)
posts.each do |post|
p "Post: #{post.at('link').inner_text}"
end
@caike
caike / a_smell.rb
Created November 28, 2012 15:43
Tell, Don't Ask.
class SomeClass
def some_method(obj)
if obj.foo
obj.bar
end
end
end
class SomeOtherClass
@caike
caike / error.rb
Created May 19, 2012 14:35
nested begin;rescue;end
class FooError < StandardError
end
begin
p "about to raise Foo.."
raise FooError.new
rescue FooError
p 'rescues from Foo'
begin
p 'about to raise Meh..'
@caike
caike / 01.Dockerfile
Last active August 10, 2021 14:38
Learn the differences between ENVs and ARGs in Docker
FROM alpine:latest
# 01- ENV set directly in Dockerfile.
# Available during BUILDTIME and RUNTIME.
ENV LOCAL_ENV="hi I am LOCAL_ENV"
RUN echo $LOCAL_ENV
# 02 - ARG sent via command (docker or docker-compose)
# Available during BUILDTIME only.
ARG BUILDTIME_ENV
@caike
caike / migration.exs
Last active July 5, 2021 15:57
snippets para o blog post sobre mix task
defmodule GuitarStore.Repo.Migrations.AddIsCustomShopToGuitars do
use Ecto.Migration
def change do
alter table("guitars") do
add :is_custom_shop, :boolean, default: false
end
create index("guitars", ["is_custom_shop"])
end
@caike
caike / agent.config.json
Created June 1, 2021 12:05
AWS CloudWatch agent simple config for CPU and memory monitoring
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"append_dimensions": {
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
Ruby 1.9.0.0 compile error (openssl problem)
TAGS: None
Found these error:
view sourceprint?
compiling openssl
gcc -I. -I../../.ext/include/i686-darwin10.2.0 -I../.././include -I../.././ext/openssl -DRUBY_EXTCONF_H=\"extconf.h\" -fno-common -g -O2 -pipe -fno-common -o openssl_missing.o -c openssl_missing.c
In file included from openssl_missing.c:22:
@caike
caike / nome-do-service.service
Created February 26, 2021 02:54
systemd config example
[Unit]
Description=O Nome do Service
[Service]
Type=notify
ExecStart=/bin/pra/iniciar/o/service
WatchdogSec=30s
Restart=always
RestartSec=5
@caike
caike / user-data-for-nginx.sh
Created December 21, 2020 17:17
Install nginx on Amazon Linux 2
#!/bin/bash -xe
yum update -y
amazon-linux-extras install nginx1 -y
cd /usr/share/nginx/html
echo "WebServer on instance-id " > index.html
curl http://169.254.169.254/latest/meta-data/instance-id >> index.html
systemctl start nginx