Skip to content

Instantly share code, notes, and snippets.

View pcostesi's full-sized avatar

Pablo Alejandro Costesich pcostesi

View GitHub Profile

Get started with [Mocha] testing

Make a package.json file if you don't have one yet:

npm init
# just keep pressing enter.
# this will create the file `package.json`
@rkh
rkh / Scala
Created April 2, 2010 19:08
examples for sinatra like frameworks
package com.thinkminimo.step
class StepExample extends Step {
get("/") { "Hello World!" }
}
@pcostesi
pcostesi / example.py
Created August 15, 2012 03:43
Flask view decorator to dispatch a request into different handlers by mimetypes.
@split
@login_required
def hello():
return render_template('hello.html')
@hello.for_mimetype("application/json")
@login_required
def hello():
return jsonify({"hello":"flask"})
/* Python(ish) string formatting:
* >>> format('{0}', ['zzz'])
* "zzz"
* >>> format('{x}', {x: 1})
* "1"
*/
var format = (function() {
var re = /\{([^}]+)\}/g;
return function(s, args) {
return s.replace(re, function(_, match){ return args[match]; });
(incomplete)
This question comes up often here. As a Windows systems engineer that transitioned into a "DevOps" systems engineer (this is a very contentious title, but "systems engineer that IS DevOps" doesn't have the same ring to it) over about a year, I'd like to start a living FAQ/guide on how to get into this game.
I'm also posting it on Gist [here](https://gist.github.com/carlosonunez/83312c12f884444620a495ef60882945). I presume that I'll update that one more frequently.
# Materials Required
* A healthy love for learning (DevOps is very young and is evolving almost daily)
* Patience with being the "dumb guy in the room"
@urkh
urkh / bulk_upsert.py
Created April 17, 2019 19:07 — forked from aisayko/bulk_upsert.py
Postgresql bulk upsert in Python (Django)
def bulk_upsert(model, fields, values, by):
"""
Return the tuple of (inserted, updated) ids
"""
result = (None, None)
if values:
stmt = """
WITH data_set AS (
INSERT INTO %s (%s)
@bitdivine
bitdivine / capped_json.sql
Last active November 8, 2021 14:52
Postgres capped collection
-- Capped collection of JSON blobs: (Use json for postgres 9.4 and below and jsonb for 9.5 and above)
CREATE SEQUENCE circle_index START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 5 CACHE 1 CYCLE ;
CREATE TABLE circle ( i integer PRIMARY KEY default nextval('circle_index') NOT NULL, tim timestamp DEFAULT current_timestamp NOT NULL, dat jsonb );
INSERT INTO circle(i, dat) SELECT nextval('circle_index') as idx, '{"a":12345,"b":1}' AS val ON CONFLICT (i) DO UPDATE SET i=EXCLUDED.i, tim=DEFAULT, dat=EXCLUDED.dat;
INSERT INTO circle(i, dat) SELECT nextval('circle_index') as idx, '{"a":12345,"b":2}' AS val ON CONFLICT (i) DO UPDATE SET i=EXCLUDED.i, tim=DEFAULT, dat=EXCLUDED.dat;
INSERT INTO circle(i, dat) SELECT nextval('circle_index') as idx, '{"a":12345,"b":3}' AS val ON CONFLICT (i) DO UPDATE SET i=EXCLUDED.i, tim=DEFAULT, dat=EXCLUDED.dat;
INSERT INTO circle(i, dat) SELECT nextval('circle_index') as idx, '{"a":12345,"b":4}' AS val ON CONFLICT (i) DO UPDATE SET i=EXCLUDED.i, tim=DEFAULT, dat=EXCLUDED.dat;
INSER
@kennethreitz
kennethreitz / flaskapp.py
Created June 9, 2012 15:38
My typical flask app base
# -*- coding: utf-8 -*-
import os
from flask import Flask
from flask_heroku import Heroku
from flask_sslify import SSLify
from raven.contrib.flask import Sentry
from flask.ext.celery import Celery
@datagrok
datagrok / gist:2199506
Last active April 8, 2023 17:36
Virtualenv's `bin/activate` is Doing It Wrong
@JanJakes
JanJakes / 00-readme.md
Last active July 27, 2023 11:32
Ubuntu server with Nginx, uWSGI and Node.js installation & deployment setup

Ubuntu with Nginx, uWSGI & Node.js and it's deployment

This Gist contains instructions to setup Ubuntu server with Nginx, uWSGI & Node.js with that can serve for any Python apps (Django for instance) and will allow it's automatized deployment.

The content is as follows:

  • 01-ubuntu.md – A basic Ubuntu server setup.
  • 02-nginx-uwsgi-nodejs.md – Nginx, uWSGI and Node.js installation and setup.
  • 03-deployment.md – A server setup for automatized deployment.
  • 04-mariadb.md – Mariadb installation and setup.