Skip to content

Instantly share code, notes, and snippets.

View dmajda's full-sized avatar

David Majda dmajda

View GitHub Profile
@dmajda
dmajda / indentation-based.pegjs
Created November 27, 2015 15:00
Simple intentation-based language PEG.js grammar
/*
* Simple Intentation-Based Language PEG.js Grammar
* ================================================
*
* Describes a simple indentation-based language. A program in this language is
* a possibly empty list of the following statements:
*
* * S (simple)
*
* Consists of the letter "S".
@dmajda
dmajda / README.txt
Created September 2, 2020 14:19
Files reproducing a bug in `pytest-asyncio`
This Gist contains files reproducing a bug in `pytest-asyncio` that appears
when testing an aiohttp application. The bug is a regression. The last good
version is 0.12.0, the first bad version is 0.14.0 (it looks like there is no
0.13.0).
Without the bug:
```console
$ pip3 install -r requirements-0.12.0.txt
$ pytest > pytest-output-0.12.0.txt
@dmajda
dmajda / gist:7688943
Created November 28, 2013 08:49
Simple PEG.js grammar to parse a markup language with nested elements (like XML)
Content =
(Element / Text)*
Element =
startTag:StartTag content:Content endTag:EndTag {
if (startTag != endTag) {
throw new Error(
"Expected </" + startTag + "> but </" + endTag + "> found."
);
}
@dmajda
dmajda / gist:1926638
Created February 27, 2012 19:58
Semantic predicates and label visibility in PEG.js
/*
* Task: Parse even numbers in PEG.js (http://pegjs.majda.cz).
*
* Solution: Let's parse all numbers and reject odd ones using a semantic
* predicate -- an arbitrary piece of code that returns true (meaning "continue
* parsing") or false (meaning "halt parsing").
*
* This solution wouldn't work before commit a2af1fe612 because predicates
* didn't have access to labeled expressions in the grammar as variables
* (without ugly workarounds). But they have the access now and the solution
@dmajda
dmajda / sqlite-history-https.txt
Created January 10, 2017 14:13
Determining percentage of HTTPS URLs in my browser history
$ sqlite3 History 1 ↵
SQLite version 3.8.10.2 2015-05-20 18:17:19
Enter ".help" for usage hints.
sqlite> SELECT COUNT(*) FROM urls WHERE url LIKE 'https://%';
20231
sqlite> SELECT COUNT(*) FROM urls;
29485
sqlite> SELECT 20231 / 29485.0; -- `.0` forces float division
0.6861454977107
@dmajda
dmajda / sanity-check.sh
Created August 5, 2016 11:03
sanity-check.sh
#!/bin/sh
# A script I used as a sanity check that PEG.js works with a particular version
# of Node.js.
#
# Example usage:
#
# nvm use 6.3.1 && PEGJS_DIR=../pegjs ./sanity-check.sh
#
#!/bin/sh
# Script to reproduce https://github.com/pegjs/pegjs/issues/434.
#
# Copy into an empty directory and run:
#
# $ sh 434.sh
mkdir src
mkdir lib
Call
= id:ID params:Params+ {
var result = {
type: "var",
name: id
};
for (var i = 0; i < params.length; i++) {
result = {
type: "call",
inuit ~ » free
total used free shared buffers cached
Mem: 8178344 2183072 5995272 0 116532 621840
-/+ buffers/cache: 1444700 6733644
Swap: 15999996 0 15999996
def check_classes
# Get list of all subclasses of Scanny::Checks::Check.
classes = []
ObjectSpace.each_object(Class) do |klass|
classes << klass if klass < Scanny::Checks::Check
end
# Filter out classes that are a superclass of some other class in the list.
# This way only "leaf" classes remain.
classes.reject do |klass|