Skip to content

Instantly share code, notes, and snippets.

View karlcow's full-sized avatar
⛩️
Working from … anywhere

Karl Dubost karlcow

⛩️
Working from … anywhere
View GitHub Profile
@karlcow
karlcow / nb.py
Created January 22, 2013 15:01
Script to take notes in the console
#!/usr/bin/env python2.7
# encoding: utf-8
import datetime
import os.path
import logging
import cmd
ROOT = "~/test/"
NOTENAME = "notes.md"

General context

  • A static website using a generator (like Jekyll)
  • Comments are in a folder, one comment = one JSON file (attached to article based on path + filename)
  • website is versionned using git, repository hosted by github (cool for pull-requests)

Posting a new comment

OK here we need some dynamism ;)

@karlcow
karlcow / blog-comments.md
Last active August 25, 2022 17:44
Decentralized Commenting Systems or more exactly how do we interconnect blog posts.

Threading discussions in between blogs

A recurrent discussion is happening in the French Web community about comments and blogs and how to continue to publish on your own blogs and still aggregates the discussion into a thread in your own blog. So basically how the discussions can be decentralized and distributed with a notion of multiple copies.

Hashtag

Let's use #sudwebcmt for the hashtag. It will help avoid putting plenty of people in cc in the discussions.

References

@karlcow
karlcow / conflicting-headers.md
Created February 27, 2013 18:29
Multiple HTTP Headers with the same field name

In 8.3.1. Considerations for New Header Fields, not really an appropriate place

Authors of specifications defining new header fields are advised to
consider documenting:

o  Whether the field is a single value, or whether it can be a list
   (delimited by commas; see Section 3.2 of [Part1]).

If it does not use the list syntax, document how to treat messages

@karlcow
karlcow / top10tweetreply.md
Created March 1, 2013 03:27
Top 10 of my tweet replies

So this came a bit as a surprise. It's all French people. I got it with

grep \"@  tweets.csv | sed -e 's/^.*"@/@/' | sed 's/ .*//' | sort | uniq -c | sort -nr | head -10

And here the Top 10 of my replies

297 @edasfr
220 @nkame

204 @fbon

@karlcow
karlcow / report.md
Created March 6, 2013 04:03
Issue with user agent sniffing, python and wikipedia
→ python3.3

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 01:25:11) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib.request
>>> opener = urllib.request.build_opener()
>>> opener.addheaders = [('User-agent', 'Python-urllib/3.3')]
>>> fobj = opener.open('http://en.wikipedia.org/robots.txt')

Traceback (most recent call last):

@karlcow
karlcow / emlx.py
Last active July 3, 2022 09:00
Parsing emlx files on Mac OS X. Apple Proprietary Storage Format for emails.
#!/usr/bin/env python
# encoding: utf-8
"""emlx.py
Class to parse email stored with Apple proprietary emlx format
Created by Karl Dubost on 2013-03-30
Inspired by Rui Carmo — https://the.taoofmac.com/space/blog/2008/03/03/2211
MIT License"""
@karlcow
karlcow / log-irc.txt
Created April 3, 2013 14:47
Getting the in/out date of my IRC chat log
Not really optimized but does the job.
grep -h "^\*\*\*\* .* \(LOGGING\|JOURNAL\)" FreeNode-\#joiito*.txt | sed -e "s/\*\*\*\* ENDING LOGGING AT /end /" | sed -e "s/\*\*\*\* FIN DU JOURNAL À/end /" | sed -e "s/\*\*\*\* BEGIN LOGGING AT /beg /" | sed -e "s/\*\*\*\* DÉBUT DU JOURNAL À/beg /" | sed -e "s/\(...\) *\(...\) \(...\) \(..\) \(..:..:..\) \(....\)$/\6-\3-\4T\5 \1/" | sed -e "s/Jan/01/" | sed -e "s/Feb/02/" | sed -e "s/Mar/03/"| sed -e "s/Apr/04/" | sed -e "s/May/05/" | sed -e "s/Jun/06/" | sed -e "s/Jul/07/" | sed -e "s/Aug/08/" | sed -e "s/Sep/09/" | sed -e "s/Oct/10/" | sed -e "s/Nov/11/" | sed -e "s/Dec/12/" | sed -e "s/\(....-..-\) /\10/" | sort > log-joiito.txt
The results is something along
2013-03-25T16:41:43 end
2013-03-25T17:40:49 beg
2013-03-26T13:51:12 end
@karlcow
karlcow / gist:5446741
Created April 23, 2013 19:40
Getting a **recursive** list of files matching a criteria (in this case '*.html')
#!/usr/bin/env python
"""
Getting a **recursive** list of files matching a criteria (in this case '*.html')
"""
import fnmatch
import os
fileslist = []
for root, dirnames, filenames in os.walk('/path/somewhere'):
for filename in fnmatch.filter(filenames, '*.html'):
@karlcow
karlcow / webmention.py
Created April 26, 2013 15:51
Prototype for a [webmention](http://webmention.org/) processor in python
#!/usr/bin/python
import cgi
import os
method = os.environ['REQUEST_METHOD']
def mimeparse(http_accept):
"Create a reduced list of mime type without quality factors"
reduced_list = []
for mime in http_accept.split(","):