Skip to content

Instantly share code, notes, and snippets.

View cavb's full-sized avatar
🚀

Cristián Vargas Busquets cavb

🚀
View GitHub Profile
-------------------------------------------------------------------------
USEFUL ONE-LINE SCRIPTS FOR SED (Unix stream editor) Dec. 29, 2005
Compiled by Eric Pement - pemente[at]northpark[dot]edu version 5.5
Latest version of this file (in English) is usually at:
http://sed.sourceforge.net/sed1line.txt
http://www.pement.org/sed/sed1line.txt
This file will also available in other languages:
Chinese - http://sed.sourceforge.net/sed1line_zh-CN.html
@cavb
cavb / README-Template.md
Created December 5, 2018 18:06 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@cavb
cavb / create_unique_slug.py
Last active June 11, 2018 18:25
Django pre_save create unique slug
@receiver(pre_save, sender=Course)
def create_slug(sender, instance, *args, **kwargs):
instance.slug = orig = slugify(instance.name)
if Course.objects.filter(slug=instance.slug).exists():
# Creates a unique slug, adding -number when its already used.
for x in itertools.count(1):
if not Course.objects.filter(slug=instance.slug).exists():
break
instance.slug = '%s-%d' % (orig, x)
@cavb
cavb / failed_connections.txt
Created November 8, 2017 04:02
Look for failed connections
grep sshd.*Did /var/log/auth.log | less
@cavb
cavb / brute-force-filter.txt
Last active November 8, 2017 04:03
Filter for brute-force interactive SSH logins
grep sshd.\*Failed /var/log/auth.log | less
@cavb
cavb / postgres_db_backup.sh
Created October 3, 2017 16:54
Backups postgres database
#!/bin/bash
logfile="/var/lib/postgresql/backups/pgsql.log"
backup_dir="/var/lib/postgresql/backups"
touch $logfile
databases=`psql -h localhost -U postgres -q -c "\l" | sed -n 4,/\eof/p | grep -v rows\) | grep -v template0 | grep -v template1 | awk {'print $1'}`
echo "Starting backup of databases " >> $logfile
for i in $databases; do
dateinfo=`date '+%Y-%m-%d %H:%M:%S'`
timeslot=`date '+%Y%m%d%H%M'`
# Replaces whitespaces with underscore of all files from this location
import os
path = os.getcwd()
filenames = os.listdir(path)
for filename in filenames:
os.rename(os.path.join(path, filename), os.path.join(path, filename.replace(' ', '_')))
@cavb
cavb / Transantiago public endpoints.md
Created July 12, 2017 03:50 — forked from radutzan/Transantiago public endpoints.md
APIs REST públicas con data del Transantiago. Respuestas en JSON.

Paraderos alrededor de un punto

http://www.transantiago.cl/restservice/rest/getpuntoparada?lat=-33.6089714&lon=-70.5742975&bip=1

Estimación de parada

http://www.transantiago.cl/predictor/prediccion?codsimt=PA420&codser=504 (código de servicio es opcional, pero el parámetro debe estar presente aunque esté vacío)

Lista de servicios

http://www.transantiago.cl/restservice/rest/getservicios/all

Info completa de servicio

@cavb
cavb / print_categories.py
Last active July 25, 2016 21:50
Python: Print only names of an array ordered by name
def print_categories(self):
''' Return categories as text for printing on templates '''
return ''.join(
[x.name +'-' for x in self.category.all().order_by('name')]
)[:-1] # Removes last '-'