Skip to content

Instantly share code, notes, and snippets.

View kosinix's full-sized avatar

Kosinix kosinix

  • Philippines
View GitHub Profile
ratio = width / height
width = height * ratio
height = width / ratio
@kosinix
kosinix / plugins_api.txt
Last active February 17, 2016 19:43
WordPress API - plugins_api keys returned
name
slug
version
author
author_profile
contributors
requires
tested
compatibility
rating
@kosinix
kosinix / compose_url.php
Created February 17, 2016 05:43
Compose URL from $_SERVER in PHP
<?php
function compose_url(array $server){
// Scheme
$scheme = '';
if (isset($server['SERVER_PROTOCOL'])) {
$scheme = explode('/', $server['SERVER_PROTOCOL']);
$scheme = strtolower($scheme[0]);
if (isset($server['HTTPS']) && 'off' != $server['HTTPS']) {
$scheme .= 's';
printf syntax
%[parameter][flags][width][.precision][length]type
https://carlalexander.ca/php-string-formatting/
@kosinix
kosinix / desaturate.php
Created June 8, 2016 07:04
Desaturate an image by a factor
<?php
$image = imagecreatefrompng( 'trees.png' );
$width = imagesx( $image );
$height = imagesy( $image );
// Create
$output = imagecreatetruecolor($width, $height);
for( $y = 0; $y < $height; $y++ ){
for( $x = 0; $x < $width; $x++ ){
@kosinix
kosinix / phpgotchas.md
Last active September 19, 2016 08:30
PHP Gotchas

SplPriorityQueue Does Not Behave Like a Queue

SplPriorityQueue is advertised as a prioritized queue. Ideally, as a queue, when adding items of the same priority, the items should retain the same order as how they were registered (FIFO). In PHP the order is unexpected:

<?php
$queue = new SplPriorityQueue();
$queue->insert('1',0);
$queue->insert('2',0);
$queue->insert('3',0);

$queue->insert('4',0);

@kosinix
kosinix / rust.md
Last active December 18, 2016 12:01
Rust primitive types range on 64 bit system
type min max
i8 -128 127
i16 -32768 32767
i32 -2147483648 2147483647
i64 -9223372036854775808 9223372036854775807
u8 0 255
u16 0 65535
u32 0 4294967295
u64 0 18446744073709551615
@kosinix
kosinix / customevents.js
Created January 29, 2017 03:39
Create custom event in plain JS. Supports modern browsers (IE11+)
// IE >= 11
function triggerEvent(el, eventName, options) {
var event,
opts = {detail: options};
event = newEvent(eventName, opts);
el.dispatchEvent(event);
}
function newEvent(eventName, options) {