Skip to content

Instantly share code, notes, and snippets.

@leomelzer
leomelzer / readme.md
Created January 5, 2012 05:36
Set proper Resolution on Linux for "Unknown Display"

The following is for the AOC 931sn.

  • Find the Recommended Resolution for your Display (on Manufacturer Website or similar)
  • Run the following in you shell
  • Press the "Auto Adjust" Button on your Display
@Quinten
Quinten / css triangle tooltip
Last active July 26, 2022 14:35
tooltip triangle on the top of an element in css
#element:before {
content: "";
position: absolute;
width: 0;
height: 0;
border-left: 16px solid transparent;
border-right: 16px solid transparent;
border-bottom: 16px solid #fff;
top: -15px;
left: 27px;
@hellysmile
hellysmile / repositories.py
Last active February 3, 2023 22:27
django repository pattern
from django.contrib.sites.models import Site
class Object(object):
def __init__(self, model, key):
self.model = model
self.key = key
def __call__(self, *args, **kwargs):
params = {}
@denji
denji / nginx-tuning.md
Last active July 20, 2024 17:33
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@edgabaldi
edgabaldi / admin.py
Created December 2, 2014 18:23
unittest for django admin calling a celery task
class PreparaLeilaoAdmin(admin.ModelAdmin):
model = Leilao
extra = 0
can_delete = False
form = LeilaoForm
def save_model(self, request, obj, form, change):
super(PreparaLeilaoAdmin, self).save_model(request, obj, form, change)
arquivo = form.cleaned_data.get('arquivo')
@leandrotoledo
leandrotoledo / main.py
Last active February 2, 2024 00:08
Webhook using self-signed certificate and Flask (with python-telegram-bot library)
#!/usr/bin/env python
'''Using Webhook and self-signed certificate'''
# This file is an annotated example of a webhook based bot for
# telegram. It does not do anything useful, other than provide a quick
# template for whipping up a testbot. Basically, fill in the CONFIG
# section and run it.
# Dependencies (use pip to install them):
# - python-telegram-bot: https://github.com/leandrotoledo/python-telegram-bot
@valyala
valyala / README.md
Last active June 3, 2024 17:00
Optimizing postgresql table for more than 100K inserts per second

Optimizing postgresql table for more than 100K inserts per second

  • Create UNLOGGED table. This reduces the amount of data written to persistent storage by up to 2x.
  • Set WITH (autovacuum_enabled=false) on the table. This saves CPU time and IO bandwidth on useless vacuuming of the table (since we never DELETE or UPDATE the table).
  • Insert rows with COPY FROM STDIN. This is the fastest possible approach to insert rows into table.
  • Minimize the number of indexes in the table, since they slow down inserts. Usually an index on time timestamp with time zone is enough.
  • Add synchronous_commit = off to postgresql.conf.
  • Use table inheritance for fast removal of old data:
@stefhen
stefhen / docker-sleep.txt
Last active January 11, 2023 18:52
Docker container sleep forever
CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait"
@oinopion
oinopion / read-access.sql
Created October 5, 2016 13:00
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;