Skip to content

Instantly share code, notes, and snippets.

View baccigalupi's full-sized avatar

Kane Baccigalupi baccigalupi

View GitHub Profile
@baccigalupi
baccigalupi / gist:1042965
Created June 23, 2011 16:48
Customized Flex Meat
switch ( yy_act )
{ /* beginning of action switch */
case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = (yy_hold_char);
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);
goto yy_find_action;
case 1:
@baccigalupi
baccigalupi / gist:1042901
Created June 23, 2011 16:23
Flex File 2
%option noyywrap
%{
/* Lexer example using a overdone c++ class for managing both tokens and logic */
#include "1_simple_calculator.cpp"
using namespace simple_calculator;
Queue token_queue;
Token token;
%}
@baccigalupi
baccigalupi / gist:1042838
Created June 23, 2011 15:55
Running Flex
flex -o 0_repeater.c 0_repeater.lex # makes an output file tokens.c from tokens.lex
# running the generated C source to make a binary
gcc 0_repeater.c -lfl -o 0_repeater
# or alternately with clang
clang 0_repeater.c -lfl -o 0_repeater
./repeater # runs the binary, will take input from the command line and run it against the code
@baccigalupi
baccigalupi / FlexFormat.c
Created June 23, 2011 15:42
Flex File format
/*
You can add include and setup C code
that will go directly into the resulting source code.
The format for getting it in their via the Flex DSL is like so:
*/
%{
/* this goes straight into the source code! */
#include 'my_file.c'
double total = 0.0;
<div class='header line'>
<div class='inner'>
<img class='logo unit size1of3' src='/my_logo.png'>
<ul class='unit size2of3'>
<li>
<a href='/login'>Login</a>
</li>
<li>
<a href='/signup'>Sign up</a>
</li>
<div class='header'>
<img class='logo' src='/my_logo.png'>
<ul>
<li>
<a href='/login'>Login</a>
</li>
<li>
<a href='/signup'>Sign up</a>
</li>
</ul>
# Available operators for overloading criteria interactions
# + & | < > <= >= =~ == <=>
# criteria creator for matching a hash/array value at a particular location
# good for hash/array objects or their derivatives
Klass.query do |obj|
obj[3] == "something" |
obj[:key] == "value"
# obj.has_value(my_value, :at => :key)
# has_value is alt syntax, could include options for :key/:index to specify hash or array
# Possible AQUA query syntax ...
# INSTANCE VARIABLES
# checks to see if a value exists, works for hashes and for arrays
@instance.has_value( value ) # value is a value or array of values
#checks to see if a value exists at a certain location
@instance.has_value( value, :at => 0 ) # if integer, assumed to be an integer
@instance.has_value( value, :at => :first ) # could be either an array or a hash key
@instance.has_value( value, :at => :some_key ) # a hash key