Skip to content

Instantly share code, notes, and snippets.

View cognominal's full-sized avatar

Stéphane Payrard cognominal

View GitHub Profile
@cognominal
cognominal / gist:181438
Created September 5, 2009 15:14
expand a rule #grammar
In S05, is there a way to "expand" a rule within another?
Example, <=v> whould expand the productions of v within a
rule so that
token t { <=v> | <d> }
token v { <a> | <b> | <c> }
Compared to C<< <=v> >>, C<< <=v> would
would avoid an additional level in the parse tree, that would
be equivalent to :
@cognominal
cognominal / gist:190613
Last active March 26, 2021 14:54
shell-to-current-directory #el
(defun shell-to-current-directory ()
"go to '*shell*' and cd it to current directory of current buffer"
(interactive "")
(let pwd default-directory)
(switch-to-buffer "*shell*")
(end-of-buffer)
(insert pwd)
(comint-send-input)
)(defun shell-to-current-directory ()
"go to '*shell*' and cd it to current directory of current buffer"
@cognominal
cognominal / gist:191045
Created September 22, 2009 12:57
conditional dereference
=head2 conditional dereference
A conditional dereference is a pattern matching and data structure
walking at once that blends well with laziness and functional
programming. A conditional dereference expression is denoted by
prefixing a dereference circumfix with either a C<?>, a C<??> or
C<?=>. When the dereference value does not exist the statement is
silently aborted if the prefix is C<?> or throws an exception if the
prefix is C<??>. In case of a silent abortion the flow proceeds
directly to the next statement, but if the conditional dereference
=head2 conditional dereference
A conditional dereference is a pattern matching and data structure
walking at once that blends well with laziness and functional
programming.
Conditional dereference are special dereference operators that work
as their not conditional counterpart if the dereference value des not
exist. Otherwise, the C<<< postcircumfix:<< < >! >> >>>, operator
thows an exception and the C<<< postcircumfix:<< < >? >> >>>
use v6;
# Null PMC access in type()
# in Main (file src/gen_setting.pm, line 295)
class SVG {
our subset Attr of Pair where { $_.value !~~ Array };
our subset Element of Pair where { $_.value ~~ Array };
our subset Text_node of Str;
our subset Node where Text_node | Element;
@cognominal
cognominal / t.coffee
Created April 3, 2011 23:30
Want to work both on node and in a browser. my problem was the scope of window and $
class Cursor
constructor: (dadDiv) ->
dadDiv.append $ "<div class='cursor'></div>"
@visible = false
toggle : ->
cursor.style.visibility =
if @visible = !@visible then 'visible' else 'hidden'
setTimeout toggle, 500
@cognominal
cognominal / aryOfObjs.js
Created April 12, 2011 12:04
What is the equivalent coffeescript syntax?
opts = [
{ name: 'lexfile',
position: 1,
help: 'Lexical grammar file (optional)'
},
{ name: 'outfile',
string: '-o FILE, --output-file=FILE',
help: 'Filename and base module name of the generated parser'
}
]
@cognominal
cognominal / nrNpmPackages.coffee
Created April 14, 2011 23:11
print the number of npm packages. I cheated : wget http://registry.npmjs.org -O registry.json #coffee
_ = require 'underscore'
fs = require 'fs'
fnm = 'registry.json'
json = JSON.parse fs.readFileSync fnm, 'utf8'
console.log (_.keys json).length
@cognominal
cognominal / branches-head-dates.coffee
Created May 6, 2011 23:20
why match is undefined at the last line of the program?
#!/usr/bin/env coffee
fs = require 'fs'
spawn = (require 'child_process').spawn
log = console.log
data = fs.readFileSync '.git/FETCH_HEAD', 'utf8'
for ln in data.split /\n/
match = /(.{40}).*?branch '(.*)'/.exec ln
continue unless match
@cognominal
cognominal / gist:977005
Created May 17, 2011 18:06
fast track complaint to commit in the master
[17:44] cognominal: ryah, in child_process.js, setupChannel uses ascii as encoding, why not utf8?
[17:44] ryah: why utf8?
[17:44] Aikar: cognominal: he just responded to the commit about that
[17:45] cognominal: in Europe, we use plenty of characters that don't fit in ascii
[17:45] ryah: this is an american project
[17:45] Aikar: lolz
[17:45] ryah: so... sorry
[17:46] tjholowaychuk: america fuck yeah
[17:46] MooGoo: yea fuck those off brand characters
[17:46] Bonuspunkt: ^^ <3