Skip to content

Instantly share code, notes, and snippets.

@mdamien
mdamien / fst2json.py
Last active November 3, 2019 20:03
GeoSteiner output parser and import to blender
"""
FST (Full Steiner tree) generator Version 3 parser
Documentation: http://geosteiner.com/geosteiner-5.1-manual.pdf (page 186)
How to use: "./rand_points 10 | ./efst | ./bb -f | python3 fst2json.py"
To note, an alternate method is to grep for the " % @C XXX YYY" output from `bb`,
to get the Steiner points. (page 158 of the manual)
"""
@mdamien
mdamien / 3way_merge.py
Created October 23, 2019 22:53
3-way merge with diff-match-patch
import os, glob
import diff_match_patch as dmp_module
dmp = dmp_module.diff_match_patch()
stashed = False
for file in glob.glob('textes_des_reglements/**/*.md'):
# (FR) commit à partir duquel les corrections ont été manuelles
@mdamien
mdamien / git_file_persistence.py
Created April 7, 2019 08:59
mwpersistence4git.py
import mwpersistence
import deltas
import mwreverts
import sys
from pathlib import Path
import git
@mdamien
mdamien / sort_replies.js
Created March 25, 2019 14:45
Sort twitter replies by likes
[].slice.call(document.querySelectorAll('.replies-to .stream-items:first-child .ProfileTweet-action--favorite .ProfileTweet-actionButton .ProfileTweet-actionCountForPresentation'))
.map(x => parseInt(x.textContent))
.filter(x=>x)
.sort((a, b) => b - a);
// to paste into the dev console when viewing a tweet replies
// output is the sorted list of number of likes for each reply
@mdamien
mdamien / wikipedia_page_authorship.py
Created March 19, 2019 10:39
wikipedia: page authorship information by wikiwho
# limitation: Special:Export method 1000 revisions limit (without pagination)
from WikiWho.examples.process_xml_dump import process_xml_dump
from WikiWho.utils import iter_rev_tokens
xml_file_path = '/home/ecu/repos/WikiWho/export_radio_meuh.xml' # export from Special:Export
wikiwho_obj = process_xml_dump(xml_file_path)
print(wikiwho_obj.title)
print(wikiwho_obj.ordered_revisions)
prev = None
@mdamien
mdamien / liquid_democracy.py
Created March 1, 2019 15:08
liquid_democracy demo
from collections import Counter
users = [1, 2, 3, 4, 5, 6, 7, 8]
delegs = {
4: 1,
5: 2,
6: 3,
7: 5,
8: 5,
import sys, os, collections, string, math
Result = collections.namedtuple('Result',
['file', 'matches', 'n_lines',
'n_exact_match', 'n_exact_length',
'title_match'])
def remove_accents(s):
table = collections.defaultdict(lambda: None)
@mdamien
mdamien / _stats
Created September 12, 2017 12:54
hatvp
pays - 90 values, 4 distincts
----
95.6% (86) FRANCE
2.2% (2) France
1.1% (1) ROYAUME-UNI
1.1% (1)
categorieOrganisation.label - 90 values, 7 distincts
@mdamien
mdamien / sokoban.py
Last active August 17, 2017 09:43
sokoban for echo phone
import sys
"""
X = WALL
P = Player
C = Box
E = Emplacement for Box
# = E + P
$ = E + C
"""
@mdamien
mdamien / 0readme.md
Last active February 22, 2024 12:11
404 link detector with scrapy

List all the broken links on your website

Requirements:

python3 and scrapy (pip install scrapy)

Usage

  • scrapy runspider -o items.csv -a site="https://yoursite.org" 1spider.py
  • python3 2format_results.py