Skip to content

Instantly share code, notes, and snippets.

@boy3vil
boy3vil / jquery parse clean URL
Created April 18, 2015 04:49
jquery parse clean URL
var url = 'example.com/hello/world/20111020/';
//get rid of the trailing / before doing a simple split on /
var url_parts = url.replace(/\/\s*$/,'').split('/');
//since we do not need example.com
url_parts.shift();
Now url_parts will point to the array ["hello", "world", "20111020"].
@boy3vil
boy3vil / OpenGL GLUT
Last active August 29, 2015 14:17
OpenGL GLUT
Download GLUT >> http://www.mediafire.com/?5329nj635679663
Akan ada file glut.h, glut32.lib, dan glut32.dll
Copy file glut.h ke dalam folder C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl
Copy file glut32.lib ke dalam folder C:\Program Files\Microsoft Visual Studio 10.0\VC\lib
Copy file glut32.dll ke dalam folder C:\Windows\System32
Catatan: untuk windows 64 bit, letakkan glut32.dll pada ‘C:\Windows\SysWOW64\’
@boy3vil
boy3vil / PHP include to variable
Created March 19, 2015 03:19
PHP include to variable
<?php
ob_start(); // turn on output buffering
include('/path/to/include.php');
$res = ob_get_contents(); // get the contents of the output buffer
ob_end_clean(); // clean (erase) the output buffer and turn off output buffering
?>
<?php
$res = file_get_contents('http://your_server/path/to/include.php');
?>
@boy3vil
boy3vil / PHP id_rec microtime
Created March 15, 2015 16:40
PHP id_rec microtime
//id_rec generator
function id_rec($set = 0){
$microtime = microtime();
$comps = explode(' ', $microtime);
$ms=sprintf('%d%03d', $comps[1], $comps[0] * 1000);
$ms=substr($ms,-3);
return date("YmdHis", time()).sprintf("%03d", ($ms+$set));
}
@boy3vil
boy3vil / sql record every user acses
Created March 15, 2015 10:00
sql record every user acses
CREATE TABLE IF NOT EXISTS `mitm` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`request_time` datetime NOT NULL,
`request_time_old` int(10) NOT NULL,
`remote_address` text COLLATE latin1_general_ci NOT NULL,
`remote_host` text COLLATE latin1_general_ci NOT NULL,
`remote_port` text COLLATE latin1_general_ci NOT NULL,
`x_forwarded_for` text COLLATE latin1_general_ci NOT NULL,
`http_via` text COLLATE latin1_general_ci NOT NULL,
`user_agent` text COLLATE latin1_general_ci NOT NULL,
@boy3vil
boy3vil / jQuery sort JSON by value
Created March 6, 2015 03:37
jQuery sort JSON by value
<script type="text/javascript">
var arr = [
{ "ID": 135, "Name": "Fargo Chan", "Address": "34, Baker Street" },
{ "ID": 432, "Name": "Aaron Luke", "Address": "BLDG 1, J Street" },
{ "ID": 252, "Name": "Dilip Singh", "Address": "Hotel J, SE" }
];
// Before Sorting
document.write("<b>Before Sorting </b><br/>");
for (var n = 0; n < arr.length; n++) {
@boy3vil
boy3vil / SQL vertical to horizontal without Transpose
Last active August 29, 2015 14:16
SQL vertical to horizontal without Transpose
#table -------------------------------------------------------------------------------------------
Roll_No | Subject | Marks
---------------------------
1212324 | MTH | 90
1212324 | PHY | 72
1212324 | CHE | 85
1212324 | BIO | 78
1212334 | MTH | 85
1212334 | PHY | 65
@boy3vil
boy3vil / jQuery replace image broken
Created March 4, 2015 04:14
jQuery replace image broken
function imgError(image) {
image.onerror = "";
image.src = "/images/noimage.gif";
return true;
}
<img src="image.png" onerror="imgError(this);"/>
OR
@boy3vil
boy3vil / jQuery cut string ...
Created March 4, 2015 04:02
jQuery cut string ...
var str = 'abcdefghi';
cut_string(str);
//return : abcde...
// cut string if length more then 5 character
function cut_string(str){
return (str.length > 5 ? str.substring(0,5)+'...' : str);
}
@boy3vil
boy3vil / jQuery parse parameter string url
Created February 28, 2015 04:13
jQuery parse parameter string url
alert(url_variable('my_url')['data1']);
//parse parameter string url
function url_variable(url){
var vars = [], hash;
//var url = "../develop/dashboard/?data1=2&data2=4";
var hashes = url.slice(url.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{