Skip to content

Instantly share code, notes, and snippets.

View alejandrobernardis's full-sized avatar
🐻

Alejandro M. BERNARDIS alejandrobernardis

🐻
View GitHub Profile
db.adminCommand("listDatabases").databases.forEach( function (d) {
if (d.name != "local" && d.name != "admin" && d.name != "config")
db.getSiblingDB(d.name).dropDatabase();
})
@alejandrobernardis
alejandrobernardis / points.sql
Created January 30, 2014 08:37
Calculo depuntos
select distinct points.user_id as user_id, points.total-redeem.total as total
from (
select tickets.id_cliente as user_id, sum(tickets.puntos_obtenidos) as total
from tickets where aprobado=1 and cancelado=0 group by tickets.id_cliente
) points
left join (
select articulos_recibidos.id_cliente as user_id, sum(articulos_recibidos.puntos) as total
from articulos_recibidos group by articulos_recibidos.id_cliente
) redeem on redeem.user_id=points.user_id
order by user_id asc;
@alejandrobernardis
alejandrobernardis / auth.py
Last active May 23, 2022 06:13
Tornado, Class Role, Permission, Identity (+mixin) and AuthContext
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2013 Asumi Kamikaze Inc.
# Copyright (c) 2013 The Octopus Apps Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
# Author: Alejandro M. Bernardis
# Email: alejandro.bernardis at gmail.com
# Created: 04/Oct/2013 09:37
import urllib
@alejandrobernardis
alejandrobernardis / c8dap.sh
Created January 16, 2014 16:47
Mongo DB ops
#!/bin/bash
REPORT_DATE=$(date +%Y%m%dT%H%M%S)
REPORT_PATH=`pwd`/r${REPORT_DATE}
# Clean
rm -fR ${REPORT_PATH}
rm -f *.json
mkdir -p ${REPORT_PATH}
# Drop DB
op = db.devices.aggregate([{
$project: {
date: 1,
newDate: {
year: {
$year: '$created'
},
month: {
$month: '$created'
},
#!/bin/sh
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
@alejandrobernardis
alejandrobernardis / mongo.js
Created January 4, 2014 22:01
Create a new collection with the old indexes
var i, c,
co_name, co_new,
co_old, co_old_i,
_db = db.getSiblingDB('logs'),
_colls = ['activity.games', 'activity.session', 'activity.social', 'activity.store'];
for (i in _colls){
co_name = _colls[i];
co_old = _db[co_name];
co_old_i = co_old.getIndexes();
# Copyright (c) 2010, Philip Plante of EndlessPaths.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
def db(self, database=None):
_ref = None
_settings = self.settings.get('database')
if _settings:
if database:
_databases = _settings.get('databases')
if database not in _databases:
raise KeyError('Database "%s" is not supported.' % database)
database = _databases.get(database)
else:
@alejandrobernardis
alejandrobernardis / ssh.sh
Created October 23, 2013 14:53
SSH // With Out Timeout
TCPKeepAlive yes
ClientAliveInterval 30
ClientAliveCountMax 99999