Skip to content

Instantly share code, notes, and snippets.

@efrenfuentes
efrenfuentes / gist:8049016
Created December 20, 2013 01:17
OrderedDict on Python
# Simple version for Python 2.7+
my_ordered_dict = json.loads(json_str, object_pairs_hook=collections.OrderedDict)
# Or for Python 2.4 to 2.6
import ordereddict
my_ordered_dict = json.loads(json_str, object_pairs_hook=ordereddict.OrderedDict)
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural /([aeiou])([A-Z]|_|$)/, '\1s\2'
inflect.plural /([rlnd])([A-Z]|_|$)/, '\1es\2'
inflect.plural /([aeiou])([A-Z]|_|$)([a-z]+)([rlnd])($)/, '\1s\2\3\4es\5'
inflect.plural /([rlnd])([A-Z]|_|$)([a-z]+)([aeiou])($)/, '\1es\2\3\4s\5'
inflect.singular /([aeiou])s([A-Z]|_|$)/, '\1\2'
inflect.singular /([rlnd])es([A-Z]|_|$)/, '\1\2'
inflect.singular /([aeiou])s([A-Z]|_)([a-z]+)([rlnd])es($)/, '\1\2\3\4\5'
inflect.singular /([rlnd])es([A-Z]|_)([a-z]+)([aeiou])s($)/, '\1\2\3\4\5'
@efrenfuentes
efrenfuentes / pushbullet.py
Created February 3, 2015 05:38
Get Pushbullet notifications
import websocket
import json
import logging
import datetime
api_key = 'Put your API Key here'
url = 'wss://stream.pushbullet.com/websocket/' + api_key
logging.basicConfig(filename='pushbullet.log', level=logging.INFO,
format='%(asctime)s:%(levelname)s:%(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
@efrenfuentes
efrenfuentes / pushbullet.rb
Created February 3, 2015 19:18
Get Pushbullet notifications
require 'faye/websocket'
require 'eventmachine'
require 'json'
require 'logger'
api_key = 'Put your API Key here'
url = 'wss://stream.pushbullet.com/websocket/' + api_key
logger = Logger.new('pushbullet.log')
logger.level = Logger::INFO
# download latest libevent2 and tmux sources, and extract them somewhere
#
# at the time of writing:
# https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
# http://sourceforge.net/projects/tmux/files/latest/download?source=files
#
# don't compile tools as root, just don't do it.
# install deps
@efrenfuentes
efrenfuentes / PublicIP.py
Created August 16, 2015 00:45
Get public IP
import urllib2
import logging
from time import sleep
# how minutes wait between checks
time_between_check = 5
# setup log output
logging.basicConfig(filename='publicIP.log',
level=logging.DEBUG,
@efrenfuentes
efrenfuentes / remove-docker-containers.md
Created December 29, 2015 15:39 — forked from ngpestelos/remove-docker-containers.md
How to remove unused Docker containers and images
  1. Delete all containers

     $ docker ps -q -a | xargs docker rm
    

-q prints only the container IDs -a prints all containers

Notice that it uses xargs to issue a remove container command for each container ID

  1. Delete all untagged images
@efrenfuentes
efrenfuentes / gen_password.rb
Created January 5, 2016 16:11
Generate random password
max_password_lenght = 8
characters = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map { |i| i.to_a }.flatten
password = (0...max_password_lenght).map { characters[rand(characters.length)] }.join
puts password
@efrenfuentes
efrenfuentes / use.go
Created March 2, 2016 04:15 — forked from elithrar/use.go
go/use: Little middleware chains that could. Inspired by comments here: https://github.com/gorilla/mux/pull/36
r := mux.NewRouter()
// Single handler
r.HandleFunc("/form", use(http.HandlerFunc(formHandler), csrf, logging)
// All handlers
http.Handle("/", recovery(r))
// Sub-routers
apiMiddleware := []func(http.Handler) http.Handler{logging, apiAuth, json}
@efrenfuentes
efrenfuentes / device.py
Last active April 19, 2016 04:33
Device
import subprocess
from snimpy.manager import Manager as M
from snimpy.manager import load
import paramiko
import MySQLdb
import socket
USER = 'zenossmon'
KEY_FILE = '/home/efren/.ssh/id_rsa.pub'