Skip to content

Instantly share code, notes, and snippets.

View onjin's full-sized avatar

Marek Wywiał onjin

View GitHub Profile
@onjin
onjin / set_wallpaper.sh
Last active July 27, 2023 11:20
set wallpaper by url | directory | file, using hyprpaper | feh | betterlockcreen | print - random or last used
#!/bin/bash
## ---------------------------------------------------------------------------------- ##
## Sets random image as wallpaper, trying remote url, local folder and fallback ##
## image. Then using executor like hyprpaper, feh, betterlockscreen or just prints ##
## found image to the output. ##
## ---------------------------------------------------------------------------------- ##
## https://gist.github.com/onjin/411d7f9c6ebcaf66aa75abe6941bea55
## ---------------------------------------------------------------------------------- ##
## Example usage
@mosquito
mosquito / README.md
Last active April 21, 2024 00:42
Add doker-compose as a systemd unit

Docker compose as a systemd unit

Create file /etc/systemd/system/docker-compose@.service. SystemD calling binaries using an absolute path. In my case is prefixed by /usr/local/bin, you should use paths specific for your environment.

[Unit]
Description=%i service with docker compose
PartOf=docker.service
After=docker.service
@hayd
hayd / sns-to-slack.py
Created May 5, 2016 06:47
sns to slack aws lambda python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Follow these steps to configure the webhook in Slack:
1. Navigate to https://<your-team-domain>.slack.com/services/new
2. Search for and select "Incoming WebHooks".
@valyala
valyala / README.md
Last active April 19, 2024 13: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:
@justanr
justanr / money.py
Last active July 20, 2016 11:43
Example of a small value object representing money.
import decimal
from functools import total_ordering
from numbers import Real
class Context(object):
def __init__(self, **kwargs):
self.context = decimal.Context(**kwargs)
def __enter__(self):
with decimal.localcontext(self.context) as c:
@palankai
palankai / specification.py
Last active March 29, 2024 10:02
Python Specification Pattern
class Specification:
def __and__(self, other):
return And(self, other)
def __or__(self, other):
return Or(self, other)
def __xor__(self, other):
return Xor(self, other)
@justanr
justanr / _core.py
Last active December 14, 2023 02:47
Clean Architecture In Python
from abc import ABC, ABCMeta, abstractmethod
from collections import namedtuple
from itertools import count
PayloadFactory = namedtuple('PayloadFactory', [
'good', 'created', 'queued', 'unchanged', 'requires_auth',
'permission_denied', 'not_found', 'invalid', 'error'
])
"""
@jabbalaci
jabbalaci / pyvideo_popularity.py
Created April 19, 2015 11:10
pyvideo popularity
#!/usr/bin/env python3
# encoding: utf-8
"""
I saw a similar script on the homepage of Miguel Grinberg (the Flask book guy),
but he was using webscraping. Here I use simple API calls instead.
The script takes the presentations of a Python conference and orders the
presentations in descending order by the number of youtube views. It
is an indicator about the popularity of a video.
# coding: utf-8
# copyright 2014 tshirtman
# distributed under the GPL licence
from __future__ import division
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import ListProperty, NumericProperty, StringProperty
from kivy.clock import Clock
@plentz
plentz / nginx.conf
Last active April 24, 2024 11:15
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048