Skip to content

Instantly share code, notes, and snippets.

int parse_expression(State *st, Lexer *lx, Scope *sc, Tree *ast, int lv) {
int root = ast_parse(st, lx, ast, 0, 1);
// int ty = ast_node_type(st, ast, sc, root);
Node *node = &ast->node[root];
if(node->tag == S_PRIM && node->val == S_EQUAL) { // assignment
node = &ast->node[node->child]; // left hand side
if(node->tag != S_ID) rg_error0(node->pos, "expected identifier"); // should evaluate to a var or selector
Object *obj = rg_sym_get(st, rg_sym_find(st, node->val, sc->tx));
if (!obj) rg_error(node->pos, "undefined symbol '%s'", spool_str(st, node->val));
@andersonsp
andersonsp / pascals.pas
Last active July 15, 2019 16:47
pascal-s pretify project
{******************************************************************************
* *
* Pascal-s entered from wirth's Pascal-s document and converted for *
* ISO 7185 use. *
* *
* The original environment of pascal (CDC computer) used a special access *
* method where the input file was split into "segments" and special methods *
* were used to access these segments. I have changed things to open the file *
* "input.pas", and compile the program from there. Input and output then *
* occur from the simulated program normally. Very few changes were made to *
@andersonsp
andersonsp / quickcg.cpp
Last active December 31, 2018 15:03
Lode's Computer Graphics Tutorial - Raycasting
/*
QuickCG 20071121
Copyright (c) 2004-2007, Lode Vandevenne
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
#ifndef __STDINT_H_INCLUDED
#define __STDINT_H_INCLUDED
#include <limits.h>
#if !defined(UINT8_MAX) && defined(UCHAR_MAX) && (UCHAR_MAX) == 0xffU
typedef unsigned char uint8_t;
typedef signed char int8_t;
# define UINT8_MAX UCHAR_MAX
# define INT8_MAX CHAR_MAX
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#define streq(a, b) (!strcmp((a), (b)))
#ifndef __USE_GNU
#define __USE_GNU

http://stackoverflow.com/a/35199727

A second method I have found which greatly reduces the size of compressed gzipped data is to first convert the data to the float16 (half-precision) format and back again to float32. This produces a lot of zeros in the output stream which can shrink file sizes by around 40-60 per cent after compression. One subtlety is that the maximum float16 value is rather low, so you may want to scale your data first, e.g. in python

import numpy as np
import math
@andersonsp
andersonsp / shell_snippets.sh
Last active October 13, 2016 21:50
Shell snippets
## copy all *.example files usable files
for ex in config/*.yml.example(:t:r) do
[[ -a config/${ex} ]] || cp config/${ex}.example config/${ex}
done
# it updates _just_ one gem and uses the specified Gemfile
BUNDLE_GEMFILE=Gemfile.other bundle update --source awesome_gem
# do a loop task with a progressbar
events=4000;
@andersonsp
andersonsp / pattern_input.html
Last active September 10, 2015 19:33
Sample code for a required input field with a specific pattern
<input name="text field" value="", pattern="\d+" class="valid_number" title="El valor debe ser numérico" required="required" />
# View abbreviated SHA, description, and history graph of the latest 20 commits
l = log --pretty=oneline -n 20 --graph --abbrev-commit
# View the current working tree status using the short format
s = status -s
# Show the diff between the latest commit and the current state
d = !"git diff-index --quiet HEAD -- || clear; git --no-pager diff --patch-with-stat"
# `git di $number` shows the diff between the state `$number` revisions ago and the current state
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define LOCALS_MAX 10
#define STACK_MAX 10
typedef unsigned char byte;