Skip to content

Instantly share code, notes, and snippets.

@pimentelra
pimentelra / Vagrantfile
Last active September 10, 2019 16:16
Set UseDNS to no on RedHat machine to prevent hanging on "vagrant up" and auto extend Windows trial
config.trigger.before :up do |trigger|
trigger.ruby do |env, machine|
if machine.name.to_s == app1
trigger.info = "Disabling DNS reverse lookup in SSHD."
if Vagrant::Util::Platform.windows?
pid = spawn("ping -n 61 127.0.0.1 > nul && for /F \"tokens=1,2 delims= \" %i in ('\"VBoxManage list runningvms | findstr /R /C:\"#{machine.name}\"\"') do VBoxManage --nologo guestcontrol %j --username root --password vagrant start --exe \"/usr/bin/sh\" -- sh/arg0 -c \"/usr/bin/sed -ie 's/\\(#\\)\\{0,1\\}UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config && /usr/bin/systemctl restart sshd\" --wait-stdout\" ")
else
pid = spawn("sleep 30 && VBoxManage --nologo guestcontrol $(VBoxManage list runningvms | grep \"#{machine.name}\" | cut -d \" \" -f 2) --username root --password vagrant start --exe \"/usr/bin/sh\" -- sh/arg0 -c \"/usr/bin/sed -ie 's/\\(#\\)\\{0,1\\}UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config && /usr/bin/systemctl restart sshd\" --wait-stdout ")
end
puts "UseDNS=no an
@pimentelra
pimentelra / log_rotate.sh
Created August 22, 2019 16:16
Bash script to compress and rotate nginx logs
#!/usr/bin/env bash
log_name='log_prefix'
for f in /var/log/nginx/${log_name}*.log; do
pattern="(.*)($log_name)(.*)"
[[ "$f" =~ $pattern ]]
/bin/gzip ${f} && /bin/kill -USR1 $(cat /run/nginx.pid) && /bin/mv ${f}.gz /var/log/nginx/$(date +%F-%T)${BASH_REMATCH[3]}.gz
done
@pimentelra
pimentelra / generate_domain_certificate.bat
Created July 18, 2019 13:18
OpenSSL certificates generation scripts
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
CLS
ECHO.
ECHO Generating Self-Signed Certificate
ECHO ==================================
@pimentelra
pimentelra / nginx.conf
Last active July 17, 2019 13:24 — forked from Stanback/nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
map $http_origin $cors_origin_header {
default "";
"~(^|^http:\/\/)(localhost$|localhost:[0-9]{1,4}$)" "$http_origin";
"~^https://test-.-dev.example.pl$" "$http_origin"; # https://test-7-dev.example.pl
"https://test.example.com" "$http_origin";
}
map $http_origin $cors_cred {
default "";
"~(^|^http:\/\/)(localhost$|localhost:[0-9]{1,4}$)" "true";

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@pimentelra
pimentelra / auto_share_citymapper_trip.txt
Last active May 31, 2019 09:18
Tasker profile to auto share a Citymapper trip with a Telegram channel
Profile: Citymapper Auto Share (16)
Application: Citymapper
Event: AutoInput UI Action [ Configuration:Action Types: Clicks Element Text: Go ]
Enter: Auto Share Citymapper Trip (10)
A1: Stop [ With Error:Off Task: ] If [ %aielementid !~ *go_and_book_go_text* ]
<trip_share>
A2: AutoInput UI Query [ Configuration:App Package: com.citymapper.app.release Timeout (Seconds):5 ]
A3: If [ %aiid() !~ *on_journey_eta_mins* ]
A4: Stop [ With Error:Off Task: ] If [ %qtime > 10 ]
A5: Wait [ MS:20 Seconds:0 Minutes:0 Hours:0 Days:0 ]
@pimentelra
pimentelra / drop_all_objects_in_list_of_schemas.sql
Last active June 3, 2019 14:04
Drop all the objects in a schema
-- SQL SERVER
-- change values inserted in @schema_list to the schemas you want to drop the objects from
SET NOCOUNT ON;
DECLARE
@sql NVARCHAR(MAX);
SET @sql = '';
DECLARE