Skip to content

Instantly share code, notes, and snippets.

View kosinix's full-sized avatar

Kosinix kosinix

  • Philippines
View GitHub Profile
@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++ ){
printf syntax
%[parameter][flags][width][.precision][length]type
https://carlalexander.ca/php-string-formatting/
@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';
@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
ratio = width / height
width = height * ratio
height = width / ratio
@kosinix
kosinix / HTTP Multipart Form.txt
Last active October 26, 2015 23:58
HTTP multipart form sample request in plaintext and php. Make sure the boundary is correct. Notice that it must have the prefix "--" in the body but not in the header.
Content-type: multipart/form-data, boundary={$boundary}
Content-Length: {$contentLength}
--{$boundary}
content-disposition: form-data; name="field1"
{$field1}
--{$boundary}
content-disposition: form-data; name="field2"
IMAGETYPE_UNKNOWN 0
IMAGETYPE_GIF 1
IMAGETYPE_JPEG 2
IMAGETYPE_PNG 3
IMAGETYPE_SWF 4
IMAGETYPE_PSD 5
IMAGETYPE_BMP 6
IMAGETYPE_TIFF_II 7
IMAGETYPE_TIFF_MM 8
IMAGETYPE_JPEG2000 9
@kosinix
kosinix / rm-wp-revisions.sql
Created February 8, 2015 05:57
Delete WP Post revisions
DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision'