Skip to content

Instantly share code, notes, and snippets.

View mturilin's full-sized avatar

Mikhail Turilin mturilin

  • Google
  • San Francisco, CA
View GitHub Profile
import json
import unicodecsv as csv
import sys
def recursive_keys(row):
keys = set()
for k in row.keys():
if isinstance(row[k], dict):
for subkey in recursive_keys(row[k]):
@mturilin
mturilin / multi_pipe.py
Last active August 29, 2015 14:00
Python multi-threading example
from multiprocessing import Process, Pipe
import sys
import time
import random
def worker(p):
while True:
s = p.recv()
if not s:
break
@mturilin
mturilin / README.txt
Last active September 1, 2019 20:44
Word Count
Get text file from URL, count all the words, and print top 20 words with the number of times they appear in the file.
URL: http://www.gutenberg.org/files/5200/5200.txt
(please copy this *exact* URL into your code)
Sample output:
the - 34
a - 12
hello - 5
@mturilin
mturilin / quote.py
Last active February 29, 2016 23:36
Email reformatting and quoting workflow for Alfred
def find_next_space(text, start):
while start < len(text):
if text[start] == " ":
return start
else:
start += 1
return start
def find_next_non_space(text, start):
while start < len(text):
@mturilin
mturilin / Readme.txt
Created August 11, 2019 21:52
Duplicate line for XCode
sudo subl /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
add the following:
<key>Customized</key>
<dict>
<key>Duplicate Lines</key>
<string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
<key>Duplicate Current Line</key>
<string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
</dict>
@mturilin
mturilin / hypenation.swift
Created August 12, 2019 18:04
Hypenation in Swift
import Foundation
extension String {
func hungarianHyphenated() -> String {
return hyphenated(locale: Locale(identifier: "hu_HU"))
}
func hyphenated(languageCode: String) -> String {
let locale = Locale(identifier: languageCode)
return self.hyphenated(locale: locale)
@mturilin
mturilin / convert.py
Created January 26, 2020 07:44
Converst TextExpander csv to espanso yaml
#!/usr/bin/python3
import yaml
import sys
import csv
# create root yaml
matches = []
# open file
@mturilin
mturilin / commands.txt
Created February 9, 2020 20:13
Bonjour - list services
#
dns-sd -B
# all disconverable services
dns-sd -B _services._dns-sd._udp local.
@mturilin
mturilin / paste_to_devtools_console.js
Created March 29, 2020 22:04
Delete all Google Photos
for(i = 1; i<=9999; i++) {
console.log("Iteration # --> " + i);
document.querySelectorAll('div[role=checkbox]').forEach(div=>div.click());
document.querySelectorAll('div[aria-label*="Select all photos"]').forEach(div=>div.click());
await new Promise(r => setTimeout(r, 3000));
try{console.log("Selected documents count for iteration [" + i + "]: " + document.evaluate('/html/body/div[1]/div/c-wiz/c-wiz[2]/span/div[1]/div/span', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerText);}catch(ex){/*do nothing*/}
document.querySelector('button[title=Delete]').click();
await new Promise(r => setTimeout(r, 5000));
document.evaluate('//span[text()="Move to trash"]', document, null, XPathResult.ANY_TYPE, null ).iterateNext().click();
@mturilin
mturilin / logit.scpt
Last active May 19, 2020 03:04
AppleScript
to logit(log_string, log_file)
do shell script ¬
"echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬
"\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit