Skip to content

Instantly share code, notes, and snippets.

View haskellcamargo's full-sized avatar
🪲
Everything is terrible

Marcelo Camargo haskellcamargo

🪲
Everything is terrible
View GitHub Profile
@haskellcamargo
haskellcamargo / Maybe.prg
Created March 31, 2015 03:31
Maybe Monad AdvPL
#include "prelude.ch"
#include "protheus.ch"
/**
* Monadic implementation for AdvPL
* @author Marcelo Camargo
*/
Class Maybe From Monad
Method New( xVal ) Constructor
Method Bind( bFun )
@haskellcamargo
haskellcamargo / rawr-oo.php
Created April 9, 2015 00:17
Prototype based programming in PHP
<?php
namespace Phonebook
{
use \Rawr\DataType\File;
// Blueprint for Contact
$contact = Object(function ($contact)
{
$contact->has([
window.scope = 0
var replicate = function(times, char) {
var i, acc = "";
for (i = 0; i < times; i++)
acc += char
return acc
}
var dump = function(data) {
{ map, first, last, filter, each } = require "prelude-ls"
export class Port
(@name, @port) ->
@listening-to-receive = []
@listening-to-disconnect = []
console.info "[%s] created" @name
@port = chrome.runtime.connect { name: @name } if not @port
@haskellcamargo
haskellcamargo / pp_sample.erl
Created May 27, 2015 18:58
Pre-processor example
%{
#define yes true
#ignore (@) ; ignore shut up operator
#token T_CONSTANT_ENCAPSED_STRING("foo") T_CONSTANT_ENCAPSED_STRING("bar")
#translate <[T_STRING]>\<<T>\> => {
class {
public function mix(<T> $arg) {
test::mix($this, $arg);
}
}
@haskellcamargo
haskellcamargo / PipingOperator.php
Created June 3, 2015 14:32
Possible RFC - Piping operator
/**
* The piping operator (|>) is based on F# and LiveScript programming languages
* or (|) on Shell and allows you to compose functions in a stack and has
* left-associativity with lower precedence.
*/
function map(callable $fn, array $xs) {
$acc = [];
foreach ($xs as $x) {
$acc[] = $fn($xs);
}
ZEND_VM_HANDLER(173, ZEND_OF, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV)
{
USE_OPLINE
zend_free_op free_op1, free_op2;
zval *op1, *op2;
SAVE_OPLINE();
op1 = GET_OP1_ZVAL_PTR(BP_VAR_R);
op2 = GET_OP2_ZVAL_PTR(BP_VAR_R);
FREE_OP1();
FREE_OP2();
@haskellcamargo
haskellcamargo / sample.c
Created June 4, 2015 02:41
Satan fights against me
ZEND_VM_HANDLER(173, ZEND_OF, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV)
{
USE_OPLINE
zend_free_op free_op1, free_op2;
zval *op1, *op2, *result;
op1 = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R);
op2 = GET_OP2_ZVAL_PTR_UNDEF(BP_VAR_R);
do {
int result;
function curry$(f, bound){
var context,
_curry = function(args) {
return f.length > 1 ? function(){
var params = args ? args.concat() : [];
context = bound ? context || this : this;
return params.push.apply(params, arguments) <
f.length && arguments.length ?
_curry.call(context, params) : f.apply(context, params);
} : f;
@haskellcamargo
haskellcamargo / TableParser.php
Last active August 29, 2015 14:22
HOLY SHIT DON'T USE THIS WORKAROUND
<?php
/**
* @package unilsc
* @author Marcelo Camargo
* @since 2015/06/08
* @license GNU GPL v3
* P.S.: NMTBR => Not Meant To Be Readable.
*/
ini_set('display_startup_errors',1);