Skip to content

Instantly share code, notes, and snippets.

# Simple Objective-C Makefile
bin = prog
CFLAGS = -Wno-import -Wall -O2
LDFLAGS = -lobjc -lm
src := $(wildcard *.m)
objects := $(foreach file, $(src), $(basename $(file)).o)
package netutil
import (
"encoding/json"
"io/ioutil"
"net/http"
)
func GetURLContents(url string) (contents []byte, err error) {
resp, err := http.Get(url)
import urllib, urllib2
import xml.etree.ElementTree as ET
from django.conf import settings
class PagSeguro():
def pagamento(self, item_id, item_descr, item_value):
pagseguro_url = 'https://ws.pagseguro.uol.com.br/v2/checkout/'
pagseguro_email = settings.PAGSEGURO_EMAIL
pagseguro_token = settings.PAGSEGURO_TOKEN
@lucindo
lucindo / README.md
Created November 6, 2015 14:09
Using Graphite/Grafana to gather Locust.io test data

Using Locust.io with Grafana

On your locust master server:

  • Install and configure Graphite. Follow a good tutorial
  • Install and configure Grafana: tutorial

Use logra.py on your locust test file. See locustfile.py.

@lucindo
lucindo / pure.theme.bash.diff
Created February 4, 2016 03:45
Showing virtualenv on Pure theme (bash it)
diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash
index 9b145cc..c25c484 100644
--- a/themes/pure/pure.theme.bash
+++ b/themes/pure/pure.theme.bash
@@ -30,12 +30,13 @@ pure_prompt() {
ps_root="${red}\u${red}";
ps_root_mark="${red} # ${normal}"
ps_path="${yellow}\w${normal}";
+ ps_env="$(virtualenv_prompt)${normal}"
@lucindo
lucindo / check_process.py
Last active February 16, 2016 01:09
sends a report of running process on servers
import sys
import subprocess
import smtplib
from email.mime.text import MIMEText
from threading import Thread
FROM = ""
TO = ""
SMTP_SERVER = "localhost"
#include <sys/klog.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
int logsize = klogctl(10 /* SYSLOG_ACTION_SIZE_BUFFER */, 0, 0);
char *bufp = malloc(logsize);
klogctl(3 /* SYSLOG_ACTION_READ_ALL */, bufp, logsize);
write(1, bufp, logsize);
From: https://www.youtube.com/watch?v=BHhA_ZKjyxo
# session management
tmux ls (or tmux list-sessions)
tmux new -s session-name
Ctrl-b d Detach from session
tmux attach -t [session name]
tmux kill-session -t session-name
# Helper class for statistics
# see: http://www.johndcook.com/blog/standard_deviation/
class Stats:
""" Uses Welford's method to calculate stats.
Assumes positive values.
It's not thread safe
stats = Stats("ConnectionTimeStats")
stats.add(0.223)
stats.add(1.343)
@lucindo
lucindo / Timer.py
Last active August 25, 2017 16:48
import time
# Simple Timer
class Timer:
def __init__(self):
self.reset()
def reset(self):
self._start = time.time()
def elapsed(self): # elapsed time in seconds (float)