Skip to content

Instantly share code, notes, and snippets.

View dmrz's full-sized avatar
👽

Dima dmrz

👽
View GitHub Profile
@dmrz
dmrz / macos-ramdisk.md
Created September 21, 2020 15:27 — forked from htr3n/macos-ramdisk.md
Creating RAM disk in macOS

Built-in

diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nobrowse -nomount ram://XXXXX`

where XXXXX is the size of the RAM disk in terms of memory blocks.

Notes:

@dmrz
dmrz / postgres_queries_and_commands.sql
Created September 13, 2020 12:31 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@dmrz
dmrz / patch-edid.md
Created February 1, 2018 15:59 — forked from ejdyksen/patch-edid.md
A script to fix EDID problems on external monitors in Mac OS. Source: http://embdev.net/topic/284710

patch-edid.rb

A script to fix EDID problems on external monitors in Mac OS.

  1. Connect the problem monitor.

  2. Download this script into your /System/Library/Displays/Overrides (note: this file is only writeable by root, so some commands require sudo).

@dmrz
dmrz / anydict.py
Last active January 31, 2018 20:10
from collections import UserDict
from unittest.mock import ANY
class AnyDict(UserDict):
"""
Returns a dict that will use unittest.mock.ANY
as a value for keys that present in dict it is
going to be compared with for equality (or not equality),
but not in dict itself. It will also ensure that comparing
@dmrz
dmrz / api.js
Created September 12, 2016 18:55
import { stringify } from 'query-string';
const _fetch = (url, config) => {
// Put query string params to url if query is given
if (config !== undefined && 'query' in config) {
url = `${url}?${stringify(config.query)}`;
}
return fetch(url, config).then(
res => {
#
# Original version by Grant Parnell is offline (http://digitaldj.net/2011/07/21/trim-enabler-for-lion/)
# Update July 2014: no longer offline, see https://digitaldj.net/blog/2011/11/17/trim-enabler-for-os-x-lion-mountain-lion-mavericks/
#
# Looks for "Apple" string in HD kext, changes it to a wildcard match for anything
#
# Alternative to http://www.groths.org/trim-enabler-3-0-released/
# Method behind this madness described: http://forums.macrumors.com/showthread.php?t=1409151&page=4
# See discussion in comments here: https://www.macupdate.com/app/mac/39654/lion-tweaks
# And here: http://forums.macrumors.com/showthread.php?t=1410459
import collections
CACHE = collections.defaultdict(set)
CACHE[1].add(1)
def divisors(n):
if not CACHE[n]:
#!/usr/bin/env python
from problem_18 import count_max_dynamically
if __name__ == '__main__':
with open('triangle.txt') as f:
data_array = [map(int, line.split()) for line in f.readlines()]
result = count_max_dynamically(data_array)
print(result)
@dmrz
dmrz / problem_18.py
Last active December 20, 2015 20:19
#!/usr/bin/env python
DATA = """\
75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
@dmrz
dmrz / problem_17.py
Last active December 20, 2015 19:49
#!/usr/bin/env python
import re
import sys
import unittest
NUMBERS = {
1: 'one',
2: 'two',
3: 'three',