Skip to content

Instantly share code, notes, and snippets.

View kosinix's full-sized avatar

Kosinix kosinix

  • Philippines
View GitHub Profile
@kosinix
kosinix / generateRandomString.php
Last active August 29, 2015 14:06
Generate Password 12 characters long with some characters removed (l,1,0,o) for readability
<?php
function generateRandomString($length = 12) {
$characters = '23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ !@#$%^&*()_-';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
@kosinix
kosinix / get_properties.php
Created September 17, 2014 01:37
Get all class properties at once and put it in an array
<?php
class Foo {
protected $var1;
protected $var2;
/* Get Properties
*
* Get all class properties at once and put it in an array
*
* @return array $class_vars
@kosinix
kosinix / resumable-download.php
Created September 22, 2014 08:46
PHP - resumable download
<?php
class ResumeDownload {
private $file;
private $name;
private $boundary;
private $delay = 0;
private $size = 0;
function __construct($file, $delay = 0) {
if (! is_file($file)) {
@kosinix
kosinix / request-component-query.txt
Last active November 3, 2015 04:02
get ?term=22 silex
$request->query->get('term');
@kosinix
kosinix / gist:5ec1732db6068ec08854
Created October 30, 2014 11:12
Force shutdown windows in 60 seconds
shutdown -s -f -t 60
@kosinix
kosinix / gist:f9c451eb6f9ccf34fc35
Last active August 29, 2015 14:09
Construct URL using symfony httpfoundation request
$request->getScheme().'://'.$request->getHttpHost().$request->getBasePath().$request->getPathInfo();
@kosinix
kosinix / mklink
Created January 26, 2015 01:00
Symbolic links in windows 7
@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'
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 / 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"