Skip to content

Instantly share code, notes, and snippets.

View maxpoletaev's full-sized avatar

Max Poletaev maxpoletaev

View GitHub Profile
@maxpoletaev
maxpoletaev / custom_layout_switch.json
Created April 25, 2024 12:03
~/.config/karabiner/assets/complex_modifications
{
"title": "Custom Layout Switch",
"rules": [
{
"description": "CapsLock to switch to English layout",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "caps_lock"
"""
Usage:
urlretrieve(source_url, filename, reporthook=ProgressBar())
"""
class ProgressBar:
def __init__(self):
self.tqdm = None
@maxpoletaev
maxpoletaev / generic_linked_list.go
Last active January 15, 2022 20:55
Go Generic Linked List
package main
type Node[T any] struct {
Val T
Next *Node[T]
}
type LinkedList[T any] struct {
Head *Node[T]
Tail *Node[T]
type Error struct {
parent error
msg string
}
func NewError(msg string) *Error {
return &Error{msg: msg}
}
func (err *Error) New(msg string) *Error {
#!/bin/bash
KEY_CODE=55 # Command Key
MAX_IDLE=30
while true; do
idle=`ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print int($NF/1000000000); exit}'`
echo "Current idle: $idle"
if [[ $idle > $MAX_IDLE ]]; then
osascript -e "tell application \"System Events\" to key code $KEY_CODE"
from django.db import models
from django.contrib import admin
from django.shortcuts import redirect
class SingletonModel(models.Model):
class Meta:
abstract = True
def save(self, *args, **kwargs):
@maxpoletaev
maxpoletaev / Makefile
Last active November 2, 2020 14:40
Help command for Makefile
# Based on https://diamantidis.github.io/tips/2020/07/01/list-makefile-targets
# With support of multiple words in the help meessage
.DEFAULT_GOAL := help
.PHONY: help test
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sed -n 's/^\(.*\): \(.*\)## \(.*\)/\1;\3/p' \
| column -t -s ';'
:root {
--main-color: #FCAF1B;
--second-color: #F17124;
}
/* admin header */
#header {
background: var(--main-color);
}
from typing import Union, Any, List, Tuple, Dict
import copy
_ExpressionTuple = Tuple[str, str, Any]
_Expression = Union[str, _ExpressionTuple]
_ExpressionOrBuilder = Union[_Expression, "WhereClauseBuilder"]
class WhereClauseBuilder:
"""
from functools import wraps
import inspect
def singleton(func):
@wraps(func)
def decorator():
if not hasattr(func, "instance"):
func.instance = func()
return func.instance