Skip to content

Instantly share code, notes, and snippets.

View junquera's full-sized avatar
🐈‍⬛

Javier JUNQUERA SÁNCHEZ junquera

🐈‍⬛
View GitHub Profile
@junquera
junquera / reverse_postgres.sh
Created February 10, 2018 23:11
SSH reverse_tunnel
REMOTE_PORT=5432
LOCAL_PORT=5432
ssh -L $REMOTE_PORT:localhost:$LOCAL_PORT $REMOTE_HOST -N
@junquera
junquera / iptables.sh
Created February 9, 2018 22:01
Quick iptables
HOST_1="192.168.1.10"
HOST_2="192.168.1.11"
HOST_1(){
echo "HOST_1 config..."
iptables -A INPUT -p tcp --dport 5432 -j ACCEPT
}
HOST_2(){
echo "HOST_2 config..."
@junquera
junquera / mongo_cheatsheet.py
Created November 28, 2017 22:05
My first mongodb python program (as cheatsheet)
#!/usr/bin/env python
# Following the tutorial at: http://api.mongodb.com/python/current/tutorial.html#
from pymongo import MongoClient
# Client connection
client = MongoClient('localhost', 27017)
# DB Name
db = client.test
@junquera
junquera / bit_pos.py
Created November 4, 2017 22:53
Get/Set bit position of an integer
def set_pos(i, p, v):
return i ^ 2**p if v else i - 2**p
def get_pos(i, p):
pos_b = 2**(p-1)
res = ((i ^ ((2**9-1) ^ pos_b)) & pos_b)
return 1 if res > 0 else 0
@junquera
junquera / string_format.js
Created October 5, 2017 14:29
String format javascript
// From https://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format/4673436#4673436
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
@junquera
junquera / update_db_owner.sh
Created September 20, 2017 15:13
Script for updating owner of a PostgreSQL db and al its tables
DB_HOST=$1
DB_PORT=$2
DB_NAME=$3
DB_USER=$4
DB_SUPERUSER=$5
psql -h $DB_HOST -p $DB_PORT -U $DB_SUPERUSER -c "ALTER DATABASE $DB_NAME OWNER TO $DB_USER;"
for i in $(psql -h $DB_HOST -p $DB_PORT -d $DB_NAME -U $DB_SUPERUSER \
-c "select tablename from pg_tables where schemaname = 'public'"); do
@junquera
junquera / memory_array_size.c
Created August 31, 2017 21:10
Reading array length from memory. Just for studing how data structures ar made...
#include <stdio.h>
int main(int argc, char** argv){
int* tmp = (int *) (argv - 1);
printf("argc = %d;\n", argc);
printf("memo = %d;\n", *tmp);
return 0;
}
@junquera
junquera / .gitignore
Created July 29, 2017 14:58
TeX article template
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
@junquera
junquera / iptables_cheatsheet.md
Last active July 14, 2017 08:31
Cheatsheet for allowing a port in IPTABLES

IPTables Cheatsheet

Allow port

sudo iptables -A INPUT -p tcp --dport $PORT -j ACCEPT

Drop rule

@junquera
junquera / findin.sh
Last active March 25, 2019 15:36
Find a text occurrence in all the files in a path
#!/bin/bash
PATH_TO_FIND="$1"
TEXT_TO_FIND="$2"
find $1 -type f |
while read f; do
if [ $(grep $2 "$f" | wc -l) -gt 0 ]; then
echo $f
else
if [ $(echo "$f" | grep $2 | wc -l) -gt 0 ]; then
echo $f