Skip to content

Instantly share code, notes, and snippets.

View redlotus's full-sized avatar
💭
YOLO!!! 🚀

redlotus redlotus

💭
YOLO!!! 🚀
View GitHub Profile
@redlotus
redlotus / client.py
Last active August 29, 2015 14:16 — forked from EyalAr/client.py
from subprocess import Popen, PIPE
from time import sleep
# run the shell as a subprocess:
p = Popen(['python', 'shell.py'],
stdin = PIPE, stdout = PIPE, stderr = PIPE, shell = False)
# issue command:
p.stdin.write('command\n')
# let the shell output the result:
sleep(0.1)
@redlotus
redlotus / about.txt
Last active August 29, 2015 14:16 — forked from jessejlt/about.txt
downloading file - flask
Okay so here's the setup:
[-] The primary server API is exposed via Flask (Python) and all static files, including all html, css, js is served by nginx.
[-] Python is exposing an API at url http://domain.com/api/download/<file_id>, where file_id is a database id for the file that we're interested in downloading.
1. User wants to download a file, so we spawn a new window with the url '/api/download/<file_id>'
2. Nginx intercepts the request, sees that it starts with /api/, and then forwards the request to Flask, which is being served on port 5000.
3. Flask routes the request to its download method, retrieves the pertinent data from the file_id, and constructs additional header settings to make nginx happy and to force the browser to see the file stream as a download request instead of the browser just trying to open the file in a new window. Flask then returns the modified header stream to nginx
4. Nginx is finally ready to do some work. While parsing the headers for the incoming request, it encounters "X

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@redlotus
redlotus / postgres-cheatsheet.md
Created March 2, 2016 14:44 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@redlotus
redlotus / API.md
Created August 2, 2017 08:24 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@redlotus
redlotus / docker-compose-daemon.sh
Created October 13, 2017 05:26 — forked from domachine/docker-compose-daemon.sh
run docker-compose in daemon mode and attach to web container
docker-compose up -d
docker attach myapp_web_1
@redlotus
redlotus / cors.nginxconf
Created November 7, 2017 08:13 — forked from pauloricardomg/cors.nginxconf
Nginx configuration for CORS-enabled HTTPS proxy with origin white-list defined by a simple regex
#
# Acts as a nginx HTTPS proxy server
# enabling CORS only to domains matched by regex
# /https?://.*\.mckinsey\.com(:[0-9]+)?)/
#
# Based on:
# * http://blog.themillhousegroup.com/2013/05/nginx-as-cors-enabled-https-proxy.html
# * http://enable-cors.org/server_nginx.html
#
server {
@redlotus
redlotus / slack-solarized-theme.css
Created January 18, 2018 02:48 — forked from anziem/slack-solarized-theme.css
Solarized theme for Slack (including background - not just sidebar)
#msgs_scroller_div::-webkit-scrollbar-track, #client_body::before, .client_container,
#search_terms, #client_body, #footer, ts-message, .channel_header, ts-jumper ts-jumper-container,
ts-jumper input[type="text"] {
background: #002B36 !important;
}
#client_body::before {
border-bottom: 1px solid #268BD2 !important;
}
@redlotus
redlotus / postgres_queries_and_commands.sql
Created May 11, 2018 17:17 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(query_start, clock_timestamp()), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(query_start, clock_timestamp()), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@redlotus
redlotus / pgsql_backup.sh
Created July 28, 2018 13:06 — forked from sirbrillig/pgsql_backup.sh
Postgresql daily backup script.
#!/bin/bash
#
# Backup a Postgresql database into a daily file.
#
BACKUP_DIR=/pg_backup
DAYS_TO_KEEP=14
FILE_SUFFIX=_pg_backup.sql
DATABASE=
USER=postgres