Skip to content

Instantly share code, notes, and snippets.

View ramnes's full-sized avatar

Guillaume Gelin ramnes

View GitHub Profile
@Airblader
Airblader / py3lock.py
Created May 11, 2015 16:41
Obscure only actual windows for i3lock
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
# vim:ts=2:sw=2:expandtab
import os
import xcb
from xcb.xproto import *
from PIL import Image
XCB_MAP_STATE_VIEWABLE = 2
@amcgregor
amcgregor / mongodb-faq.md
Last active November 9, 2016 14:27
A FAQ giving more detail than you ever wanted to know on a variety of MongoDB subjects.

Alice's MongoDB FAQ

Personal

Which operating system do you use for your servers?

I use Gentoo Linux, for a wide variety of reasons. Performance is a big one, with the least amount of RAM utilized on startup after a fresh install, startup times to all-services-responding of around four seconds, and broad support for operation in a cluster: distributed computing. By default it compiles packages from source, allowing the installed packages to be highly optimized for the physical hardware it is running on, however it also integrates binary package support and distributed compiling allowing one "master" host to orchestrate compilation across an entire cluster. This results in "from depclean" kernel compiliation times in the order of 40 seconds in my production cluster. I SSHFS mount the package directory from the master on the other hosts and simply install the binary packages it produces.

Hand-installing a new Gentoo build takes around ten minutes on a reasonably powered VM

#!/usr/bin/env python3
"""xev output data parser to get mouse polling rate.
Usage:
$ chmod a+x mouserate
$ xev | mouserate
"""
import sys
import re
#include "keymap_common.h"
/*
Shane's Planck Layout
http://www.keyboard-layout-editor.com/#/layouts/015d9011102619d7695c86ffe57cf441
*/
const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = KEYMAP( /* Base */
TAB, Q, W, E, R, T, Y, U, I, O, P, MINS,
class Factory(object):
model = object
def __init__(self):
self._objs = {}
def create(self, name):
self._objs[name] = type(name, self.model.__bases__, dict(self.model.__dict__))
return self._objs[name]
@skanev
skanev / README.md
Last active January 12, 2023 19:13
Syntax Highlight in Git Diff

Hacky syntax highlighting in git diff

Normally git diff would color additions green and deletions red. This is cool, but it would be even cooler if it adds syntax highlighting to those lines. This is a git pager that does so.

It parses the diff output and picks up the SHAs of files with additions and deletions. It uses [CodeRay][coderay] to highlight each file and then it extracts the lines that are shown in the diff. It then uses [term/ansicolor][color] to make a gradient from the CodeRay color and the diff color (red for deletion, green for addition) and uses it to replace the original.

I tried using rugged instead of shelling out to git show – it was faster overall, but it did incur a noticeable start up time.

Check out the image below for a demo.

def random_elsewhere_function():
raise AttributeError("oops")
class Foo(object):
@property
def bar(self):
random_elsewhere_function()
return "bar"
class ObjectList(list):
"""A list that can call its objects methods/variables and returns their
own returns in a list. Obviously, the list should contains only one type of
objects.
Example of use:
>>> foo = ObjectList(["bar", "baZ"])
>>> foo.islower()
[True, False]
>>> foo.append(42)
@Kartones
Kartones / postgres-cheatsheet.md
Last active April 18, 2025 10:32
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)
@justecorruptio
justecorruptio / 2048.c
Created April 4, 2014 03:49
Tiny 2048 in C!
M[16],X=16,W,k;main(){T(system("stty cbreak")
);puts(W&1?"WIN":"LOSE");}K[]={2,3,1};s(f,d,i
,j,l,P){for(i=4;i--;)for(j=k=l=0;k<4;)j<4?P=M
[w(d,i,j++)],W|=P>>11,l*P&&(f?M[w(d,i,k)]=l<<
(l==P):0,k++),l=l?P?l-P?P:0:l:P:(f?M[w(d,i,k)
]=l:0,++k,W|=2*!l,l=0);}w(d,i,j){return d?w(d
-1,j,3-i):4*i+j;}T(i){for(i=X+rand()%X;M[i%X]
*i;i--);i?M[i%X]=2<<rand()%2:0;for(W=i=0;i<4;
)s(0,i++);for(i=X,puts("\e[2J\e[H");i--;i%4||
puts(""))printf(M[i]?"%4d|":" |",M[i]);W-2