Skip to content

Instantly share code, notes, and snippets.

View reinaldons's full-sized avatar
👾

Reinaldo Nolasco Sanches reinaldons

👾
View GitHub Profile
@reinaldons
reinaldons / gist:851672
Created March 2, 2011 20:26
PostgreSQL - Grouping all client subscriptions and multiply unitary value by quantity only when product ID is not 64
SELECT
client.id,
client.name,
fop.start_effective_date,
fop.end_effective_date,
EXTRACT(month FROM fop.end_effective_date)::integer AS month,
SUM(CASE subscription.product_id WHEN 64 THEN subscription.unit_value ELSE subscription.unit_value * subscription.qty END) AS total
FROM
master
LEFT JOIN
@reinaldons
reinaldons / partial_flaskr_tests.py
Created May 8, 2013 00:13
MongoDB with no disk file persist
import socket
from time import sleep
import os
import unittest
import tempfile
from subprocess import Popen, PIPE
from flask import url_for
import flaskr
#!/usr/bin/env python
import cgi
import urllib
import urllib2
import sys
import cgitb
cgitb.enable()
#!/usr/bin/env python
import cgi
import urllib
import urllib2
import sys
import cgitb
cgitb.enable()
AMQ_URL = 'http://amq:8161/api/message/healthcheck.xpto?type=queue&clientId=xpto'
@reinaldons
reinaldons / jenkins-slave
Last active May 18, 2023 14:43
Arch Linux service for Jenkins Slave via JNLP agent.
JENKINS_HOME="/usr/share/java/jenkins"
LOG="/var/log/slave-jenkins.log"
JENKINS_URL="http://jenkins.url:8080"
SLAVE_COMPUTER="slave_computer_name"
REMOTE_JAR="$JENKINS_URL/jnlpJars/slave.jar"
JNLP_URL="$JENKINS_URL/computer/$SLAVE_COMPUTER/slave-agent.jnlp"
SECRET="YOUR SECRET ON JENKINS"
import json
with open('json file path') as f:
json_data = json.load(f)
json_data[0]['key'] = 'new value'
print(json.dumps(json_data))
@reinaldons
reinaldons / views.py
Last active May 9, 2021 01:55
Create CSV on-the-fly with Flask, stream_with_context and SQLAlchemy using generator
from datetime import datetime
from flask import current_app, stream_with_context, Response
from flask_blueprint_acquisition import current_blueprint
from sqlalchemy.sql import compiler
from .blueprints import base_blueprint
from .models import Acquisition, Package, Product, User
@reinaldons
reinaldons / Makefile
Last active June 15, 2020 13:47
Flask + uWSGI + Nginx
PID_FILE = '/tmp/flask_test_uwsgi.pid'
LOG_FILE = '/tmp/flask_test_uwsgi.log'
up:
uwsgi --ini uwsgi.ini --wsgi-file app.py --pidfile $(PID_FILE) --logto $(LOG_FILE) &
down:
uwsgi --stop $(PID_FILE)
@reinaldons
reinaldons / sms-gw-json-to-csv.py
Created October 30, 2015 16:08
Load a JSON generated by SMS-GW API /api/v1/products/(product_name)/messages and wwriting a CSV file with some fields
import json
import csv
from optparse import OptionParser
def json_to_csv(json_filename, csv_filename):
with open(json_filename, 'r') as json_file:
json_decoded = json.load(json_file)
with open(csv_filename, 'w') as csv_file:
import urllib
import requests
# OAuth2 Server URL
URL = 'https://oauth2.server'
# URL to redirect after login
REDIRECT_URI = 'https://redirect.url'
# Client ID and Secret Key
CLIENT_ID = ''