Skip to content

Instantly share code, notes, and snippets.

View Alex-Just's full-sized avatar

AlekseiK Alex-Just

  • Europe
View GitHub Profile
#!/usr/bin/python
import sqlite3
conn = sqlite3.connect('deleteme.sqlite')
# Create custom function in order to handle non-ASCII case-insensitive LIKE
conn.create_function('custom_upper', 1, lambda x: x.upper() if x else x)
###
""" https://www.hackerrank.com/challenges/maximize-it/problem """
import itertools
import sys
# TEST_INPUT = """3 1000
# 2 5 4
# 3 7 8 9
# 5 5 7 8 9 10"""
@Alex-Just
Alex-Just / checks.sql
Last active October 2, 2017 14:59
RECREATE DATABASE WITH NEW `LC_CTYPE`
SELECT UPPER('абв');
SELECT UPPER('абв' COLLATE "C.UTF-8");
SELECT * FROM pg_collation;
$ locale -a
@Alex-Just
Alex-Just / switch_input_source_language.json
Last active August 18, 2017 20:10
Karabiner-Elements script "Switch input source language" left_command -> English, right_command -> Russian
{
"title": "Switch input source language",
"rules": [
{
"description": "left_command -> English, right_command -> Russian",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "left_command"
# search file names using the AWS CLI:
aws s3 ls s3://bucket --recursive | grep search | cut -c 32-
# Dump container logs to file
sudo docker logs -t CONTAINER > /tmp/logs/CONTAINER.log 2>&1
# sudo docker logs -t 17039371835009_web_1 > /tmp/logs/web.log 2>&1
# sudo docker logs -t 35061773604481_web_1 2>&1 | grep '547ec48a-661f-11e7-a810-5d79ffc97f4e'
@Alex-Just
Alex-Just / django_orm.py
Last active January 11, 2019 12:43
Django
# Remove duplicate objects where there is more than one field to compare
https://stackoverflow.com/a/13700642
# Simple one-liner
UserProfile.objects.values('fullname').order_by().annotate(max_id=models.Max('owner_id'), count_id=models.Count('owner_id')).filter(count_id__gt=1)
# Print all SQL to console
'loggers': {
'django.db.backends': {
'level': 'DEBUG',
import json
pp json.loads(json.dumps(resp.data))
pp json.loads(json.dumps(obj))
@Alex-Just
Alex-Just / bash-cheatsheet.sh
Last active March 17, 2017 16:32 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
# 0. Shortcuts.
CTRL+A # move to beginning of line
CTRL+E # moves to end of line
CTRL+G # aborts the current editing command and ring the terminal bell
CTRL+K # deletes (kill) forward to end of line
CTRL+L # clears screen and redisplay the line
CTRL+R # searches backward
@Alex-Just
Alex-Just / bash.sh
Last active November 11, 2019 16:38
Bash programming
# Infinite Loop
while true; do echo 'Hit CTRL+C'; sleep 1; done
# Video to GIF
ffmpeg -i video.mov -ss 00:00:00.000 -pix_fmt rgb8 -r 10 -f gif - | gifsicle --optimize=3 > video.gif