Skip to content

Instantly share code, notes, and snippets.

View dimied's full-sized avatar
💭
I may be slow to respond.

dimied

💭
I may be slow to respond.
View GitHub Profile
@dimied
dimied / 55-bytes-of-css.md
Created January 31, 2024 06:06 — forked from JoeyBurzynski/55-bytes-of-css.md
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@dimied
dimied / objects_arrays.md
Created January 30, 2024 13:16 — forked from nikic/objects_arrays.md
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@dimied
dimied / gist:73ed9af14300bb46ca299d424cb4536a
Created January 30, 2024 12:56 — forked from Thinkscape/gist:1136563
Very simple performance comparison - arrays vs objects (PHP 5.3.6)
# php -v
PHP 5.3.6 (cli) (built: Mar 17 2011 20:58:15)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $s[] = array("name"=>"Adam","age"=>35); }; echo memory_get_peak_usage(); ' | php
655040
# echo '<?php $s = array(); for($x=0;$x<1000;$x++){ $o = new ArrayObject; $o->name = "Adam"; $o->age = 35; $s[] = $o;} echo memory_get_peak_usage(); ' | php
887984
@dimied
dimied / isAssocArrayBench.php
Created January 30, 2024 12:56 — forked from Thinkscape/isAssocArrayBench.php
A benchmark of several methods for checking if PHP array is associative
<?php
if(!isset($argv[1])){
echo "Usage: ".$argv[0]." (number of iterations)\n";
exit(1);
}
/**
* Arrays to check
*/
$tests = array(
package main
import (
"context"
"fmt"
"io/ioutil"
"net/http"
neturl "net/url"
"time"
)
package main
import (
"encoding/json"
"testing"
)
type foo struct {
ID string `json:"_id"`
Index int `json:"index"`
@dimied
dimied / gist:7bc522db02723f7d38d2cd8403263b86
Created October 14, 2023 21:44 — forked from totherik/gist:3a4432f26eea1224ceeb
v8 --allow-natives-syntax RuntimeFunctions
Per https://code.google.com/p/v8/codesearch#v8/trunk/src/runtime.cc
%CreateSymbol
%CreatePrivateSymbol
%CreateGlobalPrivateSymbol
%NewSymbolWrapper
%SymbolDescription
%SymbolRegistry
%SymbolIsPrivate
import { delay } from 'ts-timeframe';
import { OperationRegistry } from 'reliable-caching';
const operationRegistry = new OperationRegistry('costlyFunction');
async function simulatedCall(a: number, b: number) {
// these 3 lines represent our call
await delay(200);
console.log(`calculated ${a} * ${b}`);
return a * b;
@dimied
dimied / Calisthenics.md
Created November 17, 2022 16:51 — forked from bobuss/Calisthenics.md
The 9 Rules of Object Calisthenics

Object Calisthenics outlines 9 basic rules to apply when performing the exercise:

  • One level of indentation per method.
  • Don't use the ELSE keyword.
  • Wrap all primitives and Strings in classes.
  • First class collections.
  • One dot per line.
  • Don't abbreviate.
  • Keep all classes less than 50 lines.
  • No classes with more than two instance variables.
@dimied
dimied / curry.js
Created November 16, 2022 18:24 — forked from spoike/curry.js
Simple implementation of a curry for teaching purposes
/*
* curry(fn: Function) => Function
* Simple implementation of currying a function
* Drawbacks:
* - Cannot be reused as stored args is mutable
* - Cannot use placeholders
* - Will not check argument overflow
*/
function curry(fn) {
var arity = fn.length; // check the arity of the given function