Skip to content

Instantly share code, notes, and snippets.

View vyach-vasiliev's full-sized avatar

ฬะทçะรโลนร vyach-vasiliev

  • Milky Way galaxy, planet Earth
View GitHub Profile
@vyach-vasiliev
vyach-vasiliev / pg_schema_size.sql
Created August 4, 2023 16:29 — forked from AndreyStekov/pg_schema_size.sql
Get schema size (postgres).
SELECT pg_size_pretty(sum(pg_relation_size(quote_ident(schemaname) || '.' || quote_ident(tablename)))::bigint) FROM pg_tables
WHERE schemaname = 'yourschema'
@vyach-vasiliev
vyach-vasiliev / github_clone_using_token.sh
Last active July 25, 2023 14:15 — forked from magickatt/github_clone_using_token.sh
Clone a GitHub repository using a Personal Access Token
export GITHUB_USER=user
export GITHUB_TOKEN=secret
export GITHUB_REPOSITORY=owner/repo-path
git clone https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}
# or
git clone ${GITHUB_TOKEN}@github.com/{GITHUB_REPOSITORY}.git

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@vyach-vasiliev
vyach-vasiliev / gist:24f6d68bd5d93d39e95661b818383b9e
Created December 27, 2022 11:29 — forked from linuxfood/gist:1474361
Django ModelForm custom fields in ModelAdmin
from django.contrib import admin
from django import forms
class MyModelAdmin(admin.ModelAdmin):
# ...
def get_form(self, request, obj=None, **kwargs):
form_factory = super(MyModelAdmin, self).get_form(request, obj, **kwargs)
form_factory.base_fields['my_custom_field'] = forms.CharField(widget=forms.Textarea(), required=True)
# ...
def save_model(self, request, obj, form, change):
@vyach-vasiliev
vyach-vasiliev / postgres-cheatsheet.md
Created September 5, 2022 07:43 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@vyach-vasiliev
vyach-vasiliev / dep.ts
Created April 28, 2022 16:23 — forked from Bnaya/dep.ts
ts-node + esm
export function funci() {
return "AHH HHHHAAA";
}
@vyach-vasiliev
vyach-vasiliev / pipreplace.sh
Created January 8, 2021 14:57 — forked from stucka/pipreplace.sh
Force pip to reinstall all Python packages (works great with https://gist.github.com/stucka/0ced1cc71e1a5c374a18874471636d69)
#!/bin/bash
pip freeze --local >pipfreeze.txt
pip install --upgrade --force-reinstall -r pipfreeze.txt
# second variant
#apt-get install libxml2-dev libssl-dev libffi-dev libxslt1-dev python-dev libjpeg-dev
#pip freeze --local >pipfreeze.txt
#tr '\n' ' ' < pipfreeze.txt >pipfreeze2.txt
@vyach-vasiliev
vyach-vasiliev / ddos.conf
Created November 24, 2020 11:19 — forked from mattia-beta/ddos.conf
IPtables DDoS Protection for VPS
### 1: Drop invalid packets ###
/sbin/iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP
### 2: Drop TCP packets that are new and are not SYN ###
/sbin/iptables -t mangle -A PREROUTING -p tcp ! --syn -m conntrack --ctstate NEW -j DROP
### 3: Drop SYN packets with suspicious MSS value ###
/sbin/iptables -t mangle -A PREROUTING -p tcp -m conntrack --ctstate NEW -m tcpmss ! --mss 536:65535 -j DROP
### 4: Block packets with bogus TCP flags ###
@vyach-vasiliev
vyach-vasiliev / security.conf
Created November 24, 2020 11:19 — forked from mattia-beta/security.conf
NGINX Security Config
## Block SQL injections
set $block_sql_injections 0;
if ($query_string ~ "union.*select.*\(") {
set $block_sql_injections 1;
}
if ($query_string ~ "union.*all.*select.*") {
set $block_sql_injections 1;
}
@vyach-vasiliev
vyach-vasiliev / KotlinAndroidMainApplication1.kt
Last active November 7, 2020 14:02 — forked from paraya3636/KotlinAndroidMainApplication
Kotlin Android MainApplication class for global applicationContext.
// Author Keisuke Miura
// Not object class. AndroidManifest.xml error happen.
class MainApplication : Application() {
init {
instance = this
}
companion object {
private var instance: MainApplication? = null