Skip to content

Instantly share code, notes, and snippets.

View macleginn's full-sized avatar

Dmitry Nikolayev macleginn

View GitHub Profile

Keybase proof

I hereby claim:

  • I am macleginn on github.
  • I am macleginn (https://keybase.io/macleginn) on keybase.
  • I have a public key whose fingerprint is 5977 6205 D291 C872 046E BEE8 DCE0 A9D6 0E0B 6194

To claim this, I am signing this object:

@macleginn
macleginn / mysql2csv.py
Last active June 14, 2022 10:38
Export all tables from a MySQL database as .csv files using Python 3
import pymysql
def execute(c, command):
c.execute(command)
return c.fetchall()
db = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='mysql') #, charset='utf8')
c = db.cursor()
@macleginn
macleginn / collate_emails.js
Created July 3, 2016 19:05
Put all the messages from a Gmail inbox satisfying a query into a Google document
function collateMessages() {
var searchString = "YOURQUERYHERE";
// A query can be anything that you can enter
// into the Gmail search field:
// "datageddon from:[email protected] filename:pdf"
// etc.
var doc = DocumentApp.create(searchString);
var threads = GmailApp.search(searchString);
for (var j = 0; j < threads.length; j++) {
var messages = threads[j].getMessages();
@macleginn
macleginn / measureAndPlotFormants.praat
Last active July 16, 2016 10:31
Praat editor script for plotting formants from the selected segment and printing their values along with the duration in the info window
Extract selected sound (time from 0)
endeditor
duration = Get total duration
writeInfoLine: fixed$ (duration, 3)
# Replace 5000 with 5500 for female voice.
# You may need to tweak the number of formants (2nd parameter) based on
# your data. Sometimes, if two formants are close to each other,
# it is necessary to ask for 6 formants so that they may be decoupled.
# In other cases, however, this may introduce spurious formants, and
# it is always advisable to check the spectrogram.
@macleginn
macleginn / getAveragedFormants.praat
Last active July 16, 2016 10:31
Praat editor script for getting average values of the first three formants for the selected segment
Extract selected sound (time from 0)
endeditor
duration = Get total duration
writeInfoLine: fixed$ (duration, 3)
# Replace 5000 with 5500 for female voice.
# You may need to tweak the number of formants (2nd parameter) based on
# your data. Sometimes, if two formants are close to each other,
# it is necessary to ask for 6 formants so that they may be decoupled.
# In other cases, however, this may introduce spurious formants, and
# it is always advisable to check both the spectrogram and
@macleginn
macleginn / rusgram_postprocessor.py
Created January 12, 2017 18:33
Convertor and postprocessor of .docx files prepared for rusgram.ru
import subprocess
import re
# Convert to html using pandoc and capture output
fn = 'sources/re_docx/reflexive_letuchiy_20141102_nst_site.docx'
txt = subprocess.check_output(['pandoc',
'-f', 'docx',
'-t', 'html',
fn]).decode('utf8')
@macleginn
macleginn / normalise_Kurdistan_data.py
Last active June 25, 2017 09:36
Convert the data-table of the phonologies of the languages of Kurdistan into the normalised format
import numpy as np
import pandas as pd
import re
from functools import reduce
def process_phoneme(p):
"""Normalise phonetic symbols and enforce pharyngealised treatment of emphatics."""
p = p.split('/')[0].replace(':', 'ː').replace('\u0361', '').replace('ˠ', 'ˤ').replace('\u033b', '').replace("'", 'ʰ').replace('\u032a', '')
if 'l' not in p and '\u0334' in p:
p = p.replace('\u0334', 'ˤ')
@macleginn
macleginn / Ciris_word_list.txt
Created March 5, 2018 19:28
Lexical list of Ciris
a
ab
abisses
abruptas
absistam
abstulit
ac
accendet
accepit
accepta
using DataFrames;
using Feather;
# Заранее подготовленная таблица расстояний между этносами
dist_data = Feather.read("geodistances.feather");
@everywhere dist_array = Array{Int64}(926,926);
for i = 1:926
for j = 2:927
dist_array[i,j-1] = dist_data[i,j]
end
@macleginn
macleginn / cropndisplay.html
Created August 2, 2018 16:14
A piece of JavaScript code for selecting parts of images and displaying them in the original context. Composite shapes consisting of rectangles can be cropped to their bounding box.
<html>
<head>
<meta charset="utf8">
<title>Crop’n’display demo</title>
<style>
.overlay {
padding: 30px;
width: 100vw;
height: 100vh;
position: absolute;