Skip to content

Instantly share code, notes, and snippets.

'use latest';
import bodyParser from 'body-parser';
import express from 'express';
import Webtask from 'webtask-tools';
import { MongoClient } from 'mongodb';
import { ObjectID } from 'mongodb';
const collection = 'tasks';
const server = express();
'use latest';
import sendgrid from 'sendgrid';
import { MongoClient } from 'mongodb';
const helper = sendgrid.mail;
const collection = 'users';
/**
* @param context {WebtaskContext}
*/
const sendReminder = function(context, cb, user) {
@rafaelhdr
rafaelhdr / Netperf
Created October 2, 2017 20:00
Netperf script for running on Ubuntu
# Installing (on both servers)
apt update && apt -y upgrade &&
apt install -y wget build-essential &&
wget https://github.com/HewlettPackard/netperf/archive/netperf-2.7.0.tar.gz &&
tar -zxvf netperf-2.7.0.tar.gz &&
cd netperf-netperf-2.7.0/ &&
./configure && make && make install
# Run only at server
netserver
@rafaelhdr
rafaelhdr / longwrite.sh
Created July 4, 2017 14:38
Shell long write to file
#!/bin/sh
#
# Command examples:
# time ./write.sh
# time ./write.sh 1000
#
# This will print time taken (default test, max=100000)
# real 0m1.258s
# user 0m0.816s
# sys 0m0.438s
@rafaelhdr
rafaelhdr / cherrypyserver.py
Last active February 7, 2024 19:04
Cherrypy server with Flask application
# Reason for choosing cherrypy
# https://blog.appdynamics.com/engineering/a-performance-analysis-of-python-wsgi-servers-part-2/
#
# Flask application based on Quickstart
# http://flask.pocoo.org/docs/0.12/quickstart/
#
# CherryPy documentation for this
# http://docs.cherrypy.org/en/latest/deploy.html#wsgi-servers
# http://docs.cherrypy.org/en/latest/advanced.html#host-a-foreign-wsgi-application-in-cherrypy
# Install: pip install cherrypy
@rafaelhdr
rafaelhdr / Python urllib2.urlopen like Chrome
Last active October 21, 2019 17:30
Make a urlopen on Python with headers like Chrome
import urllib2
link = "http://example.com"
r = urllib2.Request(url=link)
# r.add_header('Cookie', 'sessionid=13cxrt4uytfc6ijvgeoflmb3u9jmjuhil; csrftoken=jdEKPN8iL62hdaq1hmMuID9DMALiiDIq')
r.add_header('Upgrade-Insecure-Requests', '1')
r.add_header('Accept-Encoding', 'gzip, deflate, sdch, br')
r.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36')
r.add_header('Connection', 'keep-alive')
r.add_header('Cache-Control', 'max-age=0')
# Install Cassandra on Ubuntu
# Source: https://www.digitalocean.com/community/tutorials/how-to-install-cassandra-and-run-a-single-node-cluster-on-ubuntu-14-04
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-set-default
echo "deb http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
echo "deb-src http://www.apache.org/dist/cassandra/debian 22x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D
# Install pip on Ubuntu
# Source: http://www.saltycrane.com/blog/2010/02/how-install-pip-ubuntu/
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install --upgrade virtualenv
@rafaelhdr
rafaelhdr / amazon-signed-url.py
Last active August 29, 2015 14:22
Generate signed URL for Amazon Associates
from time import gmtime, strftime
import urllib2
import hmac
import hashlib
import base64
"""
Code to generate signed URL for Amazon Associate
I hope it is simple to understand
@rafaelhdr
rafaelhdr / fileToArray2D.js
Created May 22, 2015 13:22
Read file and convert to Array X Array
var fs = require('fs');
var outputArray = [];
var content = fs.readFileSync('map.txt').toString('utf8');
var lines = content.split('\n');
lines.forEach(function(line){
var cells = line.split(' ');
var newArray = [];
cells.forEach(function(cell){
newArray.push(parseInt(cell));