Skip to content

Instantly share code, notes, and snippets.

View andrewpetrochenkov's full-sized avatar
🔍

Andrew P andrewpetrochenkov

🔍
View GitHub Profile
@andrewpetrochenkov
andrewpetrochenkov / django-settings-ssl.py
Last active August 3, 2024 15:54
Django settings SSL HTTPS #django #ssl
# https://docs.djangoproject.com/en/dev/topics/security/#ssl-https
if '1' in str(os.getenv('SECURE_SSL')): # SECURE_SSL=1
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
@andrewpetrochenkov
andrewpetrochenkov / emoji-remove.sh
Last active August 3, 2024 15:59
emoji remove
echo "word1 :blush: word2" | sed 's/:.*://'
echo ":blush: word2" | sed 's/:.*://' | sed "s/^[ \t]*//" | sed 's/[ \t]*$//'
@andrewpetrochenkov
andrewpetrochenkov / discord-webhook-example.py
Last active August 3, 2024 16:24
discord webhook example #discord #webhook
# https://discordapp.com/developers/docs/resources/webhook#execute-webhook
import requests
import json
import os
# prevent 400 ERROR
DESCRIPTION_MAX_LENGTH = 1900
TITLE_MAX_LENGTH = 255
TIMEOUT = 5
@andrewpetrochenkov
andrewpetrochenkov / mac-register-app.sh
Last active August 3, 2024 15:52
macOS lsregister app
set ~/Applications/name.app
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "$@"
node-sass --include-path ~/node_modules ./static/src/index.scss ./static/src/index.css
@andrewpetrochenkov
andrewpetrochenkov / postgres-basename.sql
Last active August 3, 2024 14:41
postgres basename(path) function
CREATE OR REPLACE FUNCTION basename(path text) RETURNS text AS $$
SELECT reverse((regexp_split_to_array(reverse($1), '/'))[1])
$$
LANGUAGE SQL IMMUTABLE;
SELECT basename('/Users/username/git/owner/repo');
#!/usr/bin/env bash
# https://stackoverflow.com/questions/2740806/python-sqlite-database-is-locked
function sqlite3() {
executable="$(which sqlite3)" || exit
out="$("$executable" "$@" 2>&1)" && echo "$out" && return || {
[[ "$out" == *"locked"* ]] && exit; echo "$out" 1>&2 && exit 1
}
}
set -- "word1 word2 word3"
printf "/%s" $(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1")
@andrewpetrochenkov
andrewpetrochenkov / ip.sh
Last active August 4, 2024 11:05
ip internal and public
ipconfig getifaddr en1 # internal IP
curl -s ipecho.net/plain # public IP
@andrewpetrochenkov
andrewpetrochenkov / macos-startup-sound.sh
Last active August 3, 2024 15:59
macOS startup sound #macos
defaults write .GlobalPreferences com.apple.sound.beep.sound /System/Library/Sounds/Basso.aiff