Skip to content

Instantly share code, notes, and snippets.

@only-entertainment
only-entertainment / gist:5432505
Last active December 16, 2015 12:09
Quick way to get a pdb breakpoint
def set_trace():
"""
Wrapper for ``pdb.set_trace``.
"""
from config import app
if not app.debug: return
import pdb
pdb.set_trace()
@only-entertainment
only-entertainment / example.py
Created November 5, 2012 19:24
Blocking Channel Missing Nack Example
print type(ch)
<class 'pika.adapters.blocking_connection.BlockingChannel'>
print dir(ch)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_close', '_consumers', '_on_basic_deliver', '_on_basic_get', '_on_basic_get_empty', '_on_basic_get_ok', '_on_cancel_ok', '_on_channel_flow_ok', '_on_confirm_select_ok', '_on_flow_ok_callback', '_on_get_ok_callback', '_on_open_callback', '_on_remote_close', '_open', '_pending', 'add_callback', 'add_on_close_callback', 'add_on_return_callback', 'basic_ack', 'basic_cancel', 'basic_consume', 'basic_get', 'basic_get_', 'basic_publish', 'basic_qos', 'basic_recover', 'basic_recover_async', 'basic_reject', 'callbacks', 'channel_number', 'close', 'closing', 'confirm_delivery', 'consumer_tags', 'exchange_declare', 'exchange_delete', 'flow', 'queue_bind', 'queue_declare', 'queue_del
@only-entertainment
only-entertainment / print_type_dir.py
Created October 31, 2012 21:29
Show available methods on Pika blocking channel
print "Blocking Channel:"
print type(ch)
print dir(ch)
Output:
Blocking Channel:
<class 'pika.adapters.blocking_connection.BlockingChannel'>
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_close', '_consumers', '_on_basic_deliver', '_on_basic_get', '_on_basic_get_empty', '_on_basic_get_ok', '_on_cancel_ok', '_on_channel_flow_ok', '_on_confirm_select_ok', '_on_flow_ok_callback', '_on_get_ok_callback', '_on_open_callback', '_on_remote_close', '_open', '_pending', 'add_callback', 'add_on_close_callback', 'add_on_return_callback', 'basic_ack', 'basic_cancel', 'basic_consume', 'basic_get', 'basic_get_', 'basic_publish', 'basic_qos', 'basic_recover', 'basic_recover_async', 'basic_reject', 'callbacks', 'channel_number', 'close', 'closing', 'confirm_delivery', 'consumer_tags', 'exchange_declare', 'exchange_delet
@only-entertainment
only-entertainment / code_example.py
Created October 31, 2012 20:42
basic_nack missing from BlockingChannel in Pika 0.9.5
print "Blocking Channel:"
print type(ch)
print dir(ch)
# Works
ch.basic_reject(
delivery_tag=method.delivery_tag,
requeue=True,
)
@only-entertainment
only-entertainment / global_scope.c
Created September 20, 2012 21:21
Example of global scope but bad usage
#include <stdio.h>
int foo(int, int, int, int, int, int);
// Globally scoped
int a, b, c = 0;
int x = 10;
int d, e = 0;
int main(int argc, char * argv[])
{
@only-entertainment
only-entertainment / functions
Created September 20, 2012 21:08 — forked from anonymous/functions
functions
#include <stdio.h>
int foo(int, int, int, int, int, int);
int main(int argc, char * argv[])
{
// Scoped to 'main'
int a, b, c = 0;
int x = 10;
int d, e = 0;
@only-entertainment
only-entertainment / skeleton.c
Created September 11, 2012 22:47
Skeleton Code
#include <stdio.h>
// Define functions
void display_average(float);
int get_user_input(int);
float get_user_inputs(int);
float calculate_average(float, int);
int main(int argc, char * argv[]) {
float accumulator = 0.0;
@only-entertainment
only-entertainment / Function example
Created September 11, 2012 22:38
Take the average and display it with a custom display function
#include <stdio.h>
// Define functions
void display_average(float);
int main(int argc, char * argv[]) {
float accumulator = 0.0;
int num_of_times = 0;
int ii = 1;
float average = 0.0;
@only-entertainment
only-entertainment / stuff
Created September 4, 2012 19:11 — forked from anonymous/stuff
MC
#include <stdio.h>
#include <stdlib.h>
int main(int agrv, char * argc[])
{
float N = 0;
printf("Enter a number?");
scanf("%f", &N);
{
double num = N;
#include <stdio.h>
int main(int argc, char * argv[]) {
float accumulator = 0.0;
int num_of_times = 0;
int ii = 1;
float average = 0.0;
// Ask until we have a valid input
while (1) {