Skip to content

Instantly share code, notes, and snippets.

@manuelzs
manuelzs / validated_template.py
Created May 10, 2017 15:55
Check Refs in troposphere template
import warnings
from troposphere import Template as BaseTemplate, BaseAWSObject, Ref, AWSHelperFn
from troposphere import (
AWS_ACCOUNT_ID,
AWS_NOTIFICATION_ARNS,
AWS_NO_VALUE,
AWS_REGION,
AWS_STACK_ID,
@manuelzs
manuelzs / mock_popen.py
Created October 2, 2015 14:01
Mock subprocess.Popen with context manager
import subprocess
from contextlib import contextmanager
from mock import Mock, MagicMock
@contextmanager
def popen_mock():
"""
Context manager to mock subprocess calls.
@manuelzs
manuelzs / fields.py
Created June 1, 2015 17:03
Tastypie CommaSeparatedIntegerField
from tastypie.fields import CharField
from tastypie.exceptions import ApiFieldError
class CommaSeparatedIntegerField(CharField):
"""
Converts django's string field to and from a list
"""
def dehydrate(self, bundle, for_list=True):
value = getattr(bundle.obj, self.attribute, None)
@manuelzs
manuelzs / websocket_amqp.js
Created May 14, 2011 18:16
Node.js + Socket.io + AMQP
var http = require('http');
var io = require('socket.io');
var sys = require('sys');
var amqp = require('amqp');
server = http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<h1>Hello world</h1>');
});
@manuelzs
manuelzs / CustomAdapter.java
Created March 29, 2011 17:28
Layout file for creating a simple ListView in an activity
package com.example.listview;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
/*
* Copyright 2011, Manuel Zapata
*/
// Import the sonia lib
import pitaru.sonia_v2_9.*;
// Vector to store the glow of each point
int[] glow;