Skip to content

Instantly share code, notes, and snippets.

@Aerijo
Aerijo / tree_sitter_guide.md
Last active March 30, 2024 15:19
Guide to writing your first Tree-sitter grammar

Guide to your first Tree-sitter grammar

NOTE: The Tree-sitter API and documentation has changed and improved since this guide was created. I can't guarantee this is up to date.

About

Tree-sitter is the new way Atom is providing language recognition features, such as syntax highlighting, code folding, autocomplete, and more. In contrast to TextMate grammars, which work by regex matching, Tree-sitter will generate an entire syntax tree. But more on that can be found in it's own docs.

Here, we look at making one from scratch.

@wizard04wsu
wizard04wsu / accessibleMenubar.css
Last active July 1, 2020 17:58
HTML/JavaScript menu bar that can be navigated with the mouse and keyboard. Tested with the NVDA screen reader; using ARIA role="menubar" reduces noise and automatically enters focus mode. *** requires https://gist.github.com/wizard04wsu/3ec34604d7538303e9f0 ***
ul.menubar, ul.menubar ul {
list-style-type:none;
}
ul.menubar > li {
display:inline-block;
vertical-align:top;
border:1px solid red;
}
ul.menubar ul {
display:none;
@wizard04wsu
wizard04wsu / phoneNumbers.js
Created May 1, 2014 18:37
Regular Expressions for U.S. Phone Numbers
//Regular Expressions for U.S. Phone Numbers
//
//See http://en.wikipedia.org/wiki/North_American_Numbering_Plan
//
//Spaces, dashes, or periods are allowed as separators.
//Extensions can be recognized by several strings: #, x, x., ext, ext., extension
//
//Area code: $1$2
//Exchange code: $3
//Station code: $4
@wizard04wsu
wizard04wsu / modalDialog.css
Last active July 1, 2020 17:53
This script (and CSS stylesheet) allows you to create a custom modal dialog box that will not allow the user to interact with the rest of the page.
.modalMask {
display:none;
}
.modalMask.active {
display:block;
position:fixed;
top:0;
left:0;
bottom:0;
right:0;
@wizard04wsu
wizard04wsu / bookmarklet.css
Last active July 1, 2020 17:53
CSS styling for bookmarklet links ( Updated version here: https://gist.github.com/wizard04wsu/a22bb88dcafb5229320e0e02ba08ef73 )
/* just add either class .peel-br or .peel-tr to your bookmarklet link */
a.peel-br, a.peel-tr {
display:inline-block;
position:relative;
padding:0.4em 0.6em;
border:1px solid #B4B4B4;
border-radius:5px;
background-color:#E6E6E6;
color:#333;
@kolobus
kolobus / whois.db.sh
Created February 12, 2014 22:22
Get list of all active TLD's w/whois server
#!/bin/bash
# 1
wget -qO root.zone http://www.internic.net/domain/root.zone
# 2
cat root.zone | grep "IN\sNS" | awk '{print $1}' | uniq | sort | sed -r 's/\.//g' | sed '/^$/d' > zone.list 2> /dev/null
# 3
@wizard04wsu
wizard04wsu / dimensions.js
Created February 7, 2014 21:02
JavaScript functions to get dimensions of objects and to set scroll positions
//getDimensions([elem])
//setScrollPosition(elem, top, left)
(function (){
"use strict";
//**********************//
//***** Dimensions *****//
//**********************//
@wizard04wsu
wizard04wsu / dates.js
Created February 6, 2014 21:30
JavaScript Date methods
//month names, weekday names, and ordinal indicators are in English
// Date.now()
// Date.fromISOString(isoStr)
// Date.timeBetween(date1, date2)
// dat.isLeapYear()
// dat.isUTCLeapYear()
// dat.getDaysInMonth()
// dat.getUTCDaysInMonth()
// dat.getMonthName()
@wizard04wsu
wizard04wsu / changeBase.js
Last active July 30, 2022 19:45
Convert a number to a different base (e.g., from hex to decimal)
//Convert a number to a different base (e.g., from hex to decimal).
//Returns a string representation of the number, or NaN if `num` does not represent a number of the specified base.
function changeBase(num, fromRadix, toRadix){
if(!(1*fromRadix) || fromRadix%1 !== 0 || fromRadix < 2 || fromRadix > 36){
throw new RangeError(`'fromRadix' must be an integer between 2 and 36, inclusive.`);
}
if(!(1*toRadix) || toRadix%1 !== 0 || toRadix < 2 || toRadix > 36){
throw new RangeError(`'toRadix' must be an integer between 2 and 36, inclusive.`);
}
@wizard04wsu
wizard04wsu / VBArray.vbs
Last active July 1, 2020 17:57
VBScript or VBA array functions
Function getUBound(arr)
getUBound = -1
On Error Resume Next
getUBound = UBound(arr)
On Error GoTo 0
End Function
Function getLength(arr)
getLength = getUBound(arr) + 1
End Function