Skip to content

Instantly share code, notes, and snippets.

@caike
caike / agent.config.json
Created Jun 1, 2021
AWS CloudWatch agent simple config for CPU and memory monitoring
View agent.config.json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"append_dimensions": {
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
@caike
caike / attack.md
Last active May 11, 2021
XSS attack demo with innerHTML
View attack.md

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 = "<img src=x onerror=\"alert('XSS Attack')\" >";

View installing ruby-1.8.6-p111
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 Feb 26, 2021
systemd config example
View nome-do-service.service
[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 Dec 21, 2020
Install nginx on Amazon Linux 2
View user-data-for-nginx.sh
#!/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
@caike
caike / about.md
Last active Oct 17, 2020
Node.js streams 1 vs. 2
View about.md

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
caike / ec2-nginx.yml
Last active Apr 27, 2020
CloudFormation templates. Must use Linux 2 AMI images because of systemd.
View ec2-nginx.yml
---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Creates an EC2 instance with Nginx installed and running.'
Parameters:
VPC:
Description: VPC for the SecurityGroup
Type: AWS::EC2::VPC::Id
@caike
caike / dope-flan.md
Created Apr 20, 2020
Dope Brazilian Flan
View dope-flan.md
  • 3 eggs
  • 1 yolk
  • 2 cans of sweetened condensed milk
  • One of these ☝️ empty cans full of whole milk
  • A pinch of vanilla extract
@caike
caike / todo.jsx
Created Apr 11, 2015
Simple Todo app demo using React + ES6
View todo.jsx
var React = require("react");
var allItems = []
allItems.push("Buy ingredients for Crock Pot");
allItems.push("Pick up chair at IKEA");
allItems.push("Go see mom");
class TodoList extends React.Component {
constructor(props){
super(props);
@caike
caike / timer.js
Last active Oct 1, 2019
Example of updating timer on the fly
View timer.js
$(function() {
const timer = $('.timer');
timer.startTimer({ allowPause: true });
setTimeout(() => {
timer.trigger('click');
timer.data('timeLeft', 30);
timer.trigger('click');
}, 3000);
});