Skip to content

Instantly share code, notes, and snippets.

@rcarmo
rcarmo / extract.hy
Last active August 29, 2015 14:11
Readability-like HTML extraction in Hy
; originally posted on https://github.com/rodricios/eatiht/issues/2#issuecomment-67769343
(import
[collections [Counter]]
[cookielib [CookieJar]]
[lxml.etree [HTML tostring]]
[urllib2 [build-opener HTTPCookieProcessor]])
(def *min-length* 20)
(def *text-xpath* (+ "//body//*[not(self::script or self::style or self::i or self::b or self::strong or self::span or self::a)]/text()[string-length(normalize-space()) > " (str *min-length*) "]/.."))
@rcarmo
rcarmo / hazelcast-in-jython-startup.txt
Last active August 29, 2015 14:13
Hazelcast in Jython
$ export CLASSPATH=$CLASSPATH:lib/hazelcast-3.4.jar
$ python
*sys-package-mgr*: processing new jar, '/home/rcarmo/Development/jython-hazelcast/lib/hazelcast-3.4.jar'
Jython 2.7b3 (default:e81256215fb0, Aug 4 2014, 02:39:51)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_05
Type "help", "copyright", "credits" or "license" for more information.
>>> import com.hazelcast.core.Hazelcast as Hazelcast
>>> import com.hazelcast.config.Config as Config
>>> h = Hazelcast.newHazelcastInstance(Config())
jan 09, 2015 4:17:23 PM com.hazelcast.instance.DefaultAddressPicker
@rcarmo
rcarmo / blu.hy
Created March 14, 2015 09:30
Blu, a CLI tool for Azure
(import
[azure.servicemanagement [ServiceManagementService]]
[base64 [b64decode]]
[click [argument command group option]]
[json [loads dumps]]
[os [environ]]
[os.path [join]]
[OpenSSL.crypto [load-pkcs12 dump-privatekey dump-certificate *filetype-pem*]]
[subprocess [Popen *pipe*]]
[tabulate [tabulate]]
@rcarmo
rcarmo / default
Last active August 29, 2015 14:23 — forked from mzsanford/default
# Set the peer listening address
# export ETCD_PEER_ADDR=127.0.0.1:7001
# Set other command line options like the name and discovery url
# from https://discovery.etcd.io/new
# export ETCD_OPTS="-name=name_here -discovery=https://discovery.etcd.io/token_here"
export ETCD_OPTS="--data-dir '/var/run/default.etcd'"
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": ".*",
"resource-type": ["script"],
"load-type": ["third-party"],
"if-domain": ["imore.com"]
@rcarmo
rcarmo / event_hubs_send.py
Created February 2, 2016 11:01 — forked from tomconte/event_hubs_send.py
Send messages to an Azure Event Hub using the Apache Qpid Proton AMQP library.
#!/usr/bin/python
# Send messages to an Azure Event Hub using the Apache Qpid Proton AMQP library.
import sys
import commands
from proton import *
# Event Hub address & credentials
# amqps://<keyname>:<key>@<namespace>.servicebus.windows.net/<eventhubname>
@rcarmo
rcarmo / decorator.py
Created March 5, 2016 19:23 — forked from j0lvera/decorator.py
bottle.py basic auth examples
from bottle import route, run, auth_basic
from passlib.hash import sha256_crypt
def check_pass(username, password):
hashed = ''.join(redis.hmget(username, "password"))
return sha256_crypt.verify(password, hashed)
@route('/', method='GET')
@auth_basic(check_pass) # <-- decorator
def index():
@rcarmo
rcarmo / archive.txt
Created March 18, 2016 23:07
Epic Commits from @dramalho
061997d DELEGATE ALL THE THINGS
092aa231f wait, wrong place
09e7fd3 RERECORD ALL THE THINGS!!!
0c27fb3 yeah, fix things will ya
0f4549133 New ascii art task (\!important stuff) , and a few DAO tweaks (mino...
12aa7ef34 LE NONNNNNN LE MADNESS
13233e7 Less PHP
154c535 Once more, now with feeling and a proper master head
184e754 Dear Past-Friday David :Remember the textarea that seemed totally random and misterioys? It was $.ajax... obviously
19a8700 MAKE IT BIGGER
/*
Example code to get a MCP3*08 running with an ESP8266
for DiY energy monitoring solutions
*/
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "MCP3208.h"
const char* ssid = "...";
const char* host = "...";
@rcarmo
rcarmo / thespian-raft.py
Created August 7, 2016 08:17
The Raft leader election protocol, implemented atop GoDaddy's Thespian actor library
from thespian.actors import *
from datetime import datetime, timedelta
from logging import getLogger, basicConfig, DEBUG
from random import randint
basicConfig(level=DEBUG)
log = getLogger(__name__)
class Postman(Actor):