Skip to content

Instantly share code, notes, and snippets.

View furkanmustafa's full-sized avatar
💭
Set your status

Furkan Mustafa furkanmustafa

💭
Set your status
View GitHub Profile
@furkanmustafa
furkanmustafa / php-html-attr-parser.php
Created November 27, 2012 10:44
php script for parsing html element attributes
<?php
// TEST
//print_r(getTagAttributes('<img enabled href=/fuck/my/attr/syntax" disabled id="idofmyelemtnt" title="Incredible Web Site" src="/images/incredibility.jpg" style="height:300px;width:900px;" />'));
function getTagAttributes($htmlortag, $name = false) { // name=false returns all attributes as array
$p = 0;
$tag = false;
$inquote = false;
$started = false;
@furkanmustafa
furkanmustafa / html-php-date-picker.php
Created January 27, 2013 15:34
Date Picker Select Generator for HTML & PHP
<select name="year">
<option value="">Year</option>
<?php for ($year = date('Y'); $year > date('Y')-100; $year--) { ?>
<option value="<?php echo $year; ?>"><?php echo $year; ?></option>
<?php } ?>
</select>
<select name="month">
<option value="">Month</option>
<?php for ($month = 1; $month <= 12; $month++) { ?>
<option value="<?php echo strlen($month)==1 ? '0'.$month : $month; ?>"><?php echo strlen($month)==1 ? '0'.$month : $month; ?></option>
@furkanmustafa
furkanmustafa / vmstat-parser.php
Created February 7, 2013 16:35
PHP Function for parsing vmstat output
<?php
// TEST
// $res[] = "procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----";
// $res[] = " r b swpd free buff cache si so bi bo in cs us sy id wa";
// $res[] = " 0 0 0 10376 148188 291056 0 0 4 29 85 9 1 0 98 1";
// // or
// // exec('vmstat', $res);
// print_r(parseVMStatOutput($res));
@furkanmustafa
furkanmustafa / php-query-string.php
Last active December 14, 2015 22:39
PHP Functions for parsing & building query strings, in a better way than http_build_query or parse_str does.
<?php
function ParseQueryString($query, $orig = false) {
$items = $orig ? $orig : array();
$_items = explode('&', $query);
foreach ($_items as $item) {
if (strpos($item, '=')===false) {
$items[urldecode($item)] = true;
}
else {
@furkanmustafa
furkanmustafa / onMainQueue.mm
Last active December 17, 2015 04:48
simple function for running UI Updates (or anything) on main thread for Cocoa. Can be useful if you have a callback you are not sure it always runs on main thread.
void onMainQueue(void(^block)(void)) {
if ([NSThread isMainThread])
block();
else
dispatch_sync(dispatch_get_main_queue(), block);
}
//usage example:
- (void)callbackThatIDontKnowWhichThreadIsItRunningOn {
onMainQueue(^{
@furkanmustafa
furkanmustafa / putio.sh
Last active June 2, 2019 20:38
Simple Bash Script to download files from your put.io accountUsage: putio.sh "https://put-io-download-link"
#!/bin/bash
PUTIO_USERNAME="your put.io username"
PUTIO_PASSWORD="your put.io password"
wget --http-user=${PUTIO_USERNAME} --http-password=${PUTIO_PASSWORD} --content-disposition -c $@
@furkanmustafa
furkanmustafa / FMConfigurationManager.php
Last active December 17, 2015 12:09
Simple JSON Configuration Manager
<?php
/**
* A Simple JSON Site-wide Configuration manager with key-path access, overriding, inline variables, etc..
* It might look ugly for some people, most important goal with this is simplicity in the code that uses this.
*
* You can find usage sample at the end of the file
*
* @author Furkan Mustafa <furkan@fume.jp>
* @version 0.1.3
@furkanmustafa
furkanmustafa / NSBaseConversion.mm
Created May 28, 2013 02:00
Objective-C Base Conversion
/**
Original Code From, Md. Mahmud Ahsan, http://thinkdiff.net/mixed/base-conversion-handle-upto-36-bases/, 2008.02.28
Adapted Objective-C, Furkan Mustafa, 2013.05.28
Description: Alpha Numeric Base Conversion, Handles upto base 36
*/
NSString* reverseString(NSString* original) {
const char* chars = [original cStringUsingEncoding:NSASCIIStringEncoding];
int length = strlen(chars);
char* new = (char*)malloc(length+1);
@furkanmustafa
furkanmustafa / mem.class.php
Last active December 17, 2015 19:29
Easy to use memcache proxy class for php
<?php
/*
Memcache Proxy Class for data
Furkan Mustafa, 2013.05
use it.
usage:
$dataUsedTooMuch = mem::cache('myhandle', 30, function() {
return db::query('SELECT CRAZY SLOW SQL SCRIPT');
@furkanmustafa
furkanmustafa / nonBreakingExplode.php
Created July 20, 2013 14:08
Replacement for php's built-in explode function, doesn't break quotes, etc.
<?php
// a replacement for php's built-in explode function, doesn't break quotes, etc.
function nonBreakingExplode($delimiter, $string, $nobreakChars = array('"', '\'', '()', '[]')) {
$pos = 0;
$len = strlen($string);
$delimiterLen = strlen($delimiter);
$lastCut = 0;
$nest = array();