Skip to content

Instantly share code, notes, and snippets.

View lockie's full-sized avatar

Andrew Kravchuk lockie

View GitHub Profile
@lockie
lockie / trigram_migration.py
Last active January 14, 2018 11:45
A Django migration to add PostgreSQL trigram search, aka pg_trgm
# -*- coding: utf-8 -*-
# XXX this is actually useful for very special use cases, e.g. misspel suggestions:
# https://www.postgresql.org/docs/9.6/static/pgtrgm.html#AEN180626
from __future__ import unicode_literals
from django.db import migrations
from django.contrib.postgres.operations import TrigramExtension
class Migration(migrations.Migration):
operations = [
@lockie
lockie / latex-cheatsheet-template.tex
Created October 24, 2017 08:50 — forked from alexander-yakushev/latex-cheatsheet-template.tex
Beautiful cheatsheet template for key bindings, compiled with XeLaTeX
\documentclass[20pt,english,landscape]{extarticle}
\usepackage{multicol}
\usepackage{calc}
\usepackage[landscape]{geometry}
\usepackage{color,graphicx,overpic}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[utf8]{inputenc}
\usepackage{url}
alias c='cd'
alias m='mc'
alias v='vim'
alias e='emacs -nw'
alias l='ls'
alias gg='git gui'
alias dc='docker-compose'
@lockie
lockie / .spacemacs
Last active February 24, 2020 12:10
Spacemacs config to eradicate bad editing habits
;; put this to dotspacemacs/user-config
(defun left-key-stub ()
(interactive)
(message "Use Vim keys: <h> for Left, <b> for previous word"))
(define-key evil-normal-state-map (kbd "<left>") 'left-key-stub)
(define-key evil-insert-state-map (kbd "<left>") 'left-key-stub)
(define-key evil-visual-state-map (kbd "<left>") 'left-key-stub)
(defun right-key-stub ()
(interactive)
set autohidecursor
set showtabindices
set sortlinkhints
let completionengines = ["google"]
let hintcharacters = "asdfghjkl"
map <C-f> scrollFullPageDown
map <C-b> scrollFullPageUp
map <C-d> scrollPageDown
map <C-u> scrollPageUp
@lockie
lockie / wsgi.py
Last active February 17, 2018 08:33
# ...
import django
from django.utils import autoreload
import uwsgi
def reloader():
if django.conf.settings.DEBUG:
print('Starting debug reloader')
def multipliers():
return [lambda x, idx=i: idx * x for i in range(4)]
print([m(2) for m in multipliers()])
import numpy as np
np.real(-7 * np.exp(np.pi * 1j + np.log(6)))
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
%pylab inline
pylab.rcParams['figure.figsize'] = (6, 10)
x = np.linspace() #ваши цифры в скобках
y = # ваш код для функции
plt.plot(x, y);
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
class Context():
def __enter__(self):
print('__enter__')
def __exit__(self, *args):
print('__exit__')