Skip to content

Instantly share code, notes, and snippets.

class TasksController < ApplicationController
# GET /tasks
# GET /tasks.xml
def index
@tasks = Task.all
respond_to do |format|
tasks = @tasks.map {|task| json_for_task(task) }
format.json { render :json => { :content => tasks } }
format.html
@dfee
dfee / directory.py
Last active August 29, 2015 14:06
FreeSwitch mod_python Directories Example [modern]
from collections import defaultdict
import freeswitch
sound_path_prefix = "/usr/local/freeswitch/sounds/custom/"
def text_to_digit(text, len):
"""Map text to digits"""
atoi_d = {
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img alt="" src="data:image/gif;base64,R0lGODlhMQAwAPcAAAAAAAcHABUVACEhADQ0AEREREZGAElJAElJSUpKLUxMME5OOE9PM1NTN1RUAFRUVFhYAFhYPFlZIVlZWV1dQF9fCmFhAGNjY2RkD2lpAGlpTGpqFWpqamtrM3FxHHNzAHNzc3R0O3d3Inh4I3p6AH19KH19fX5+Pn9/P4CAaoKCgoODAIODLoyMAIyMN4yMjJGRPJWVAJWVJJWVlZmZAJmZKJ6enqGhTKSkAKWlpaamNKysAKysH6+vr7a2ALa2tre3Kry8ALy8Lr29vcTEGsXFxcbGAMfHOc/PAM/PJc/Pz9DQQ9TUKtbW1tnZAN3dFt3dM9/fAN/f3+PjOebmAObmIubm5u3tJu/vAO/v7/b2E/b2MPb29vj4APz8Gf7+AP7+/gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
# An example of using SQLAlchemy / PSQL for PubSub with asyncio
# Rather than using `select.select` to watch for messages, we use
# `loop.add_reader`.
# Inspired by: https://gist.github.com/dtheodor/3862093af36a1aeb8104
#
# One example of use is with aiopyramid.
#
# For an additional consideration, read about case folding here:
# http://stackoverflow.com/a/5173993/465164
@dfee
dfee / ip_regex.py
Last active December 7, 2023 19:39
Python IPV4 / IPV6 Regular Expressions (REGEX)
# Constructed with help from
# http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
# Try it on regex101: https://regex101.com/r/yVdrJQ/1
import re
IPV4SEG = r'(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])'
IPV4ADDR = r'(?:(?:' + IPV4SEG + r'\.){3,3}' + IPV4SEG + r')'
IPV6SEG = r'(?:(?:[0-9a-fA-F]){1,4})'
IPV6GROUPS = (
@dfee
dfee / executor.py
Last active May 17, 2017 22:41
Guarding functions in asphalt that should only run in an executor.
import asyncio
from asphalt.core import Context
import functools
def guard_executor(func):
no_ctx_msg = ('Context must be the first arg, or an instance variable of '
'`self` (if wrapping an instance method).')
not_in_executor_msg = '{} must be run in an executor'.format(func.__name__)
@dfee
dfee / setup.oy
Created September 24, 2017 08:06
from setuptools import setup, find_packages
setup(
name='server',
version='0.1',
packages=find_packages(),
include_package_data=True,
install_requires=[
'aiohttp',
# 'aiohttp-graphql',
@dfee
dfee / Dockerfile
Last active March 12, 2018 10:36
Debian Dockerfile with pyenv, a default python, and pipenv.
FROM debian:stable
ARG PYTHON_VERSION=3.6.2
### Setup python:{version} ###
# helpful links:
# https://github.com/pyenv/pyenv/wiki/Common-build-problems
# https://github.com/pyenv/pyenv/blob/32922007863c4a54feca2a95226c8307cfdfea3d/plugins/python-build/README.md
# https://github.com/pyenv/pyenv/issues/990
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
@dfee
dfee / graphene_subscription.py
Created November 25, 2017 03:17
Example of how subscriptions work with graphene
from collections import OrderedDict
import graphene
import rx
subject = rx.subjects.Subject()
class Author(graphene.ObjectType):
import asyncio
from inspect import iscoroutinefunction
import pytest
import rx
# pylint: disable=W0621, redefined-outer-name
def debug(value):