Skip to content

Instantly share code, notes, and snippets.

View hikari-no-yume's full-sized avatar
🌟
trying to save beautiful things

hikari_no_yume hikari-no-yume

🌟
trying to save beautiful things
View GitHub Profile
#include <cstdlib>
#include <ctime>
#define DLLEXPORT extern "C" __declspec (dllexport)
DLLEXPORT double get_time()
{
time_t currentTime, zeroTime = {0};
time(&currentTime);
return difftime(currentTime, zeroTime);
}
@hikari-no-yume
hikari-no-yume / curry.js
Last active August 29, 2015 14:01
Tiny function and operator curriers
function curry(func, arity) {
arity = (arity === undefined) ? func.length : arity;
if (arity > 1) {
return function (arg) {
var args = Array.prototype.slice.call(arguments, 0);
return function partial (arg) {
args = args.concat(Array.prototype.slice.call(arguments, 0));
if (args.length < arity) {
return partial;
} else {
@hikari-no-yume
hikari-no-yume / evil.js
Created May 9, 2014 21:30
How to mess with JavaScript programmers
var TotallyNotArray = Object.create(Array.prototype);
TotallyNotArray.constructor = Array;
var EvilArray = function () {
return Object.create(TotallyNotArray);
};
// Now do x = EvilArray(); in Chrome's dev console
// It'll show up like an array, and all operations will work...
// But there's no magic .length property! >:D
@hikari-no-yume
hikari-no-yume / bigint.patch
Last active August 29, 2015 14:02
Work-in-progress Zend bigint patch (zend_language_scanner.c's massive diff removed for the sake of readability)
From bdec0820b6933a64c388b0451c8ae0914e817aa4 Mon Sep 17 00:00:00 2001
From: Andrea Faulds <ajf@ajf.me>
Date: Fri, 6 Jun 2014 02:12:59 +0100
Subject: [PATCH] Working bigints with no tests and some unfixed corner cases
---
Zend/Makefile.am | 2 +-
Zend/Zend.dsp | 4 +
Zend/Zend.m4 | 24 +
Zend/ZendTS.dsp | 4 +
@hikari-no-yume
hikari-no-yume / tests.txt
Created June 9, 2014 23:54
Tests broken by bigints
=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #24054 (Assignment operator *= broken) [tests/lang/bug24054.phpt]
Directly modifying an unreferenced array when foreach'ing over it while using &$value syntax. [tests/lang/foreachLoop.013.phpt]
Directly modifying a REFERENCED array when foreach'ing over it. [tests/lang/foreachLoop.014.phpt]
Directly modifying a REFERENCED array when foreach'ing over it while using &$value syntax. [tests/lang/foreachLoop.015.phpt]
Test + operator : 64bit long tests [tests/lang/operators/add_basiclong_64bit.phpt]
Test & operator : 64bit long tests [tests/lang/operators/bitwiseAnd_basiclong_64bit.phpt]
Test ~N operator : 64bit long tests [tests/lang/operators/bitwiseNot_basiclong_64bit.phpt]
@hikari-no-yume
hikari-no-yume / gist:9a5ca0eb55a1d7918796
Last active August 29, 2015 14:04
->call versus ->bindTo performance
andreas-air:php-src ajf$ time sapi/cli/php -r '$a = function () { return $this->x; }; class FooBar { private $x = 3; } $foobar = new FooBar; for ($i = 0; $i < 100000; $i++) { $x = $a->bindTo($foobar, "FooBar"); $x(); }'
real 0m0.259s
user 0m0.208s
sys 0m0.012s
andreas-air:php-src ajf$ time sapi/cli/php -r '$a = function () { return $this->x; }; $a = $a->bindTo(NULL, "FooBar", true); class FooBar { private $x = 3; } $foobar = new FooBar; for ($i = 0; $i < 100000; $i++) { $a->call($foobar); }'
real 0m0.100s
user 0m0.094s
@hikari-no-yume
hikari-no-yume / problems_with_C.md
Created August 11, 2014 22:09
Problems with C
  1. Prototypes and headers. Get rid of them.
  2. Integer types. To be fair, it's not really a language problem, rather a compiler/platform issue:
    • char - almost universally 8-bit
    • short - almost universally 16-bit
    • int - supposed to be 16-bit, in practise 32-bit
    • long - supposed to be 32-bit, in practise 64-bit on UNIX-likes on AMD64
    • long long - always 64-bit

I'd make char 8-bit, short 16-bit, int 32-bit and long 64-bit consistently. long int would be removed. char would always be signed. 3. Other stuff I forgot welp

#define ggon_decode
// real/string ggon_decode(string text)
// Decodes a GGON (Gang Garrison Object Notation) text
// Returns either a string or a ds_map handle
var text;
text = argument0;
var tokens;
tokens = ggon_tokenise(text);
@hikari-no-yume
hikari-no-yume / test-convert.phpt
Created October 5, 2014 19:07
php-langspec test conversion script
<?php
function fixDir($dir) {
$files = glob($dir . '/*');
foreach ($files as $file) {
if (is_dir($file)) {
fixDir($file);
} else {
fixFile($file);
@hikari-no-yume
hikari-no-yume / make_table.php
Last active August 29, 2015 14:07
Safe Casting Functions RFC conversions table generator (see: https://wiki.php.net/rfc/safe_cast)
<?php
class NotStringable {}
class Stringable {
public function __toString() {
return "foobar";
}
}
$values = [