Skip to content

Instantly share code, notes, and snippets.

View cben's full-sized avatar

Beni Cherniavsky-Paskin cben

View GitHub Profile
@cben
cben / pandoc_filter_math2doublebackslashmath.py
Created March 18, 2014 04:52
pandoc filter to convert $..$ and $$...$$ math to \\(..\\) and \\[...\\] respectively.
#!/usr/bin/env python2
r"""
Use via ``pandoc --filter pandoc_filter_math2doublebackslashmath.py``
to convert math (in any syntax pandoc will recognize)
to \\(..\\) and \\[...\\] syntaxes (``tex_math_double_backslash`` extension).
"""
from pandocfilters import toJSONFilter, Math, RawInline, RawBlock
import sys, json
>>> import yaml # need to install PyYAML
>>> dict_1 = {'a': 0, '1': {1: {'abc': [1, 2, 3, 4, 5, 6], 'efg': [7, 8, 9, 10, 100]},
2: {'1': {1: 'abc', 2: 'efg'}, '2': {3: 'abc'}}}, '2': [1, 2, 3, 4, 5, 6]}
>>> print(yaml.safe_dump(dict_1, default_flow_style=False))
'1':
1:
abc:
- 1
- 2
@cben
cben / README.md
Created February 5, 2015 10:15
Haroopad 0.13.0 issue with inline math

haroopad-v0.13.0-x64.deb on lubuntu 14.10. Same problem both in editor preview and Export -> HTML file.

  • \sqrt{3x-1}+(1+x)^2 at the end is rendered as display math. (Same when I tried single dollars with corresponding Preferences option.)
  • the text that follows it in the paragragh disappeared.
fr = null;
try {
FileReader fr = new FileReader(file);
try {
BufferedReader br = new BufferedReader(fr);
String line = null;
} finally {
// [I'm not sure swallowing errors here is good but that's an unrelated question -- Beni]
try {
fr.close();
@cben
cben / README.md
Last active August 29, 2015 14:17
mathml fallback in email

Tried to test mail.html, as sent to myself via https://putsmail.com/tests/f742cb78-6229-450f-bfa7-494c2349e859. Copy-pasted into Mailchimp (which give interface to Litmus testing for $3/test). Alas, it seems the Mailchimp editor sanitized(?) it into actual-test.html, stripping out the MathML :-( Results below make more sense now...


Full results at https://rawgit.com/cben/51056286578d837cba46/raw/results.html (16MB of images!)

  1. MathML didn't render anywhere. Not thunderbird, not Apple Mail / iOS. I'll have to read www.maths-informatique-jeux.com/blog/frederic/?post/2012/11/14/Writing-mathematics-in-emails again and try to make it work.

[since the source blog doesn't support comments and the margins of a tweet are too narrow]

Hmm, interesting distinction. But I don't see why your way is better than having the CI build the image.

  • It is more flexible in allowing me to build the image any ad-hoc way I want, e.g. modify files inside the container and take a snapshot.
    But my primary Dev instinct is that I don't want this. The last thing I want in prod is an image I don't have sources for. I'm not thinking in terms "test this image before deploying" but in terms of "test this source code". Which means build an image from Dockerfile in a clean env, test this "clean" image (and yes, push this same image to prod).
@cben
cben / numeric_entities_to_utf8.py
Last active August 29, 2015 14:23
Convert numeric entities (`{`) to unicode
#!/usr/bin/python3
# Caution: this will convert everywhere, including inside <script>...</script> or CDATA sections.
import re, os
def numeric_entities_to_utf8(fname):
s = open(fname, encoding='utf8', newline='').read()
s = re.sub(r'&#([0-9]+);', lambda m: chr(int(m.group(1))), s)
with open(fname, 'w', encoding='utf8', newline='') as f:
@cben
cben / foo.py
Last active August 29, 2015 14:26 — forked from anonymous/foo.py
print("Hello, world!")
#!/usr/bin/env python3
class memoize(dict):
def __init__(self, func):
self.func = func
dict.__init__(self)
def __call__(self, *args):
return self[args]
def __missing__(self, key):