Skip to content

Instantly share code, notes, and snippets.

View ironworld's full-sized avatar
💭
Pianinho 🎹

Cícero Raupp Rolim ironworld

💭
Pianinho 🎹
View GitHub Profile
@Wowu
Wowu / sentry-rocketchat.js
Last active October 26, 2023 14:34
Sentry webhook integration for Rocket.Chat
class Script {
process_incoming_request({ request }) {
// console is a global helper to improve debug
console.log("Sentry error");
console.log(JSON.stringify(request.content));
var fields = [];
fields.push({
title: "Message",
@semicolom
semicolom / test_basic_auth.py
Created March 8, 2021 16:04
Django Rest Framework unit test API with Basic Auth
import base64
from rest_framework import HTTP_HEADER_ENCODING, status
from rest_framework.test import APITestCase
from user.models import User
class EndpointViewTest(APITestCase):
def test_basic_auth(self):
username = "test_username"
@czue
czue / json_tags.py
Last active December 15, 2023 21:41
A simple django template tag that lets you automatically render json from a python object
"""
Usage:
{% load json_tags %}
var = myJsObject = {{ template_var|to_json }};
Features:
- Built in support for dates, datetimes, lazy translations.
@solso
solso / autossh.sh
Created July 26, 2012 13:56
Support material for blog post of redis replication
#!/bin/sh
## --- tunnel_to_master_redis
REDIS_MASTER=XYZ
REDIS_SLAVE_PORT=6280
AUTOSSH_POLL=300
AUTOSSH_PORT=20000
AUTOSSH_GATETIME=10
AUTOSSH_LOGFILE=/var/log/autossh/autossh.log
@rochacbruno
rochacbruno / haversine.py
Created June 6, 2012 17:43
Calculate distance between latitude longitude pairs with Python
#!/usr/bin/env python
# Haversine formula example in Python
# Author: Wayne Dyck
import math
def distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination
@netaustin
netaustin / fabric.py
Created May 21, 2012 03:47
Fabric SSH Tunnel
from fabric.api import *
from fabric.contrib.console import confirm
from local_settings import remote_user
from time import time
import subprocess, shlex, atexit, time
from settings import DATABASES
from os import remove
env.use_ssh_config = True
env.context = 'local'
@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@cyberdelia
cyberdelia / mixin.py
Created September 21, 2011 08:26
Django class based view mixins
# -*- coding: utf-8 -*-
from django.contrib.auth.decorators import login_required
from django.utils.cache import patch_response_headers
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page, never_cache
from django.views.decorators.csrf import csrf_exempt
class NeverCacheMixin(object):
@method_decorator(never_cache)
@waynemoore
waynemoore / month_day_range.py
Created July 27, 2011 11:01
Get first and last day of a particular month using python-dateutil.
import datetime
# requires python-dateutil (http://labix.org/python-dateutil)
from dateutil.relativedelta import relativedelta
def get_month_day_range(date):
"""
For a date 'date' returns the start and end date for the month of 'date'.
Month with 31 days:
@dokterbob
dokterbob / fields.py
Created March 18, 2011 19:07
Email field with domain existence validation for Django.
import logging
logger = logging.getLogger(__name__)
# Note: we need dnspython for this to work
# Install with `pip install dnspython`
import dns.resolver, dns.exception
from django import forms
from django.utils.translation import ugettext as _