Skip to content

Instantly share code, notes, and snippets.

View singulared's full-sized avatar
💭
🐧

Maxim Belousov singulared

💭
🐧
View GitHub Profile
@singulared
singulared / prepare-commit-msg
Created June 17, 2021 11:10
Git hook for adding branch name into the commit message.
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".
@singulared
singulared / sway-lock.sh
Created February 12, 2020 15:37
swaylock with image per-output
#!/bin/bash
# Dependencies:
# imagemagick
# swaylock
# grim
IMAGE=/tmp/i3lock.png
LOCK=~/.config/sway/lock.png
LOCKARGS=""
@singulared
singulared / playground.rs
Last active February 5, 2020 00:03 — forked from rust-play/playground.rs
impl From variadic like :D
#[derive(Debug)]
struct CM {
id: i32,
topic_id: i32,
}
#[derive(Debug)]
struct TM {
id: i32,
}
@singulared
singulared / prepare-commit-msg
Created August 26, 2019 16:58
Git hook for adding branch name for each commit message.
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".
@singulared
singulared / state.rs
Created May 27, 2019 12:49 — forked from dbrgn/state.rs
Custom Text based Diesel type for an enum
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
#[serde(rename_all="snake_case")]
pub enum State {
Pending,
Sending,
Sent,
Failed,
}
impl fmt::Display for State {
@singulared
singulared / futures.rs
Created May 23, 2019 14:11
Collecting vector of future's results in rust
use futures; // 0.1.26
use futures::prelude::*;
use futures::future::{ok, err};
use futures::stream::*;
use futures::future::FutureResult;
fn future_result(x: i32) -> FutureResult<i32, i32> {
match x {
1 => ok(42),
@singulared
singulared / futures.rs
Created May 20, 2019 17:43
multiple futures in one function
use futures::future::*;
fn either(x: Option<i32>) -> impl Future<Item = i32, Error = i32> {
match x {
Some(x) => Either::A(ok(x).map(|x| x)),
None => Either::B(ok(42).and_then(|x| err(x)))
}
}
fn boxed(x: Option<i32>) -> Box<Future<Item = i32, Error = i32>> {
Section "InputClass"
Identifier "touchpad"
Driver "synaptics"
MatchIsTouchpad "on"
Option "TapButton1" "1"
Option "TapButton2" "2"
Option "TapButton3" "3"
Option "VertEdgeScroll" "off"
Option "VertTwoFingerScroll" "on"
Option "HorizEdgeScroll" "off"
@singulared
singulared / ensure_future.py
Created February 27, 2018 12:15
ensure_future scheduled corotine
import asyncio
async def d():
print('d start')
await asyncio.sleep(2)
print('d stop')
async def f():
print('f start')
@singulared
singulared / aiohttp_benchmark.py
Last active February 26, 2018 17:44
aiohttp benchmark
import aioredis
from aiohttp import web
async def init(app):
print('redis connecton')
app['redis'] = await aioredis.create_redis(
'redis://localhost', loop=app.loop)
async def deinit(app):