Skip to content

Instantly share code, notes, and snippets.

View remoharsono's full-sized avatar

Remo Harsono remoharsono

View GitHub Profile
@remoharsono
remoharsono / PHP - MySQL Insert with Implode
Last active September 28, 2016 08:27
Inserting data with Implode to MySQL
<?php
// source: http://stackoverflow.com/questions/779986/insert-multiple-rows-via-a-php-array-into-mysql
$sql = array();
foreach( $data as $row ) {
$sql[] = '("' . mysql_real_escape_string($row['text']) . '", ' . $row['category_id'] . ')';
}
mysql_query('INSERT INTO table (text, category) VALUES ' . implode(',', $sql));
?>
@remoharsono
remoharsono / Check If Element Exist
Created December 20, 2012 07:50
In case you do not have jQuery or any other library, just this to check whether an element is exist or not taken from http://stackoverflow.com/questions/5629684/javascript-check-if-element-exists-in-the-dom
var element = document.getElementById('elementId');
if (typeof(element) != 'undefined' && element != null)
{
// exists.
}
@remoharsono
remoharsono / format_bytes.php
Last active December 18, 2015 09:49
formatting into Kilobytes, Megabytes...//echo formatBytes(24962496);// 23.81M//echo formatBytes(24962496, 0);// 24M//echo formatBytes(24962496, 4);// 23.8061M
function formatBytes($size, $precision = 2)
{
$base = log($size) / log(1024);
$suffixes = array('', 'k', 'M', 'G', 'T');
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
}
@remoharsono
remoharsono / Javascript - Prime Number
Last active December 19, 2015 03:38 — forked from jfmercer/prime_numbers.js
Prime Number Checker in Nodejs
//
// Created by John F. Mercer on Monday, December 5, 2011
// john.f.mercer@gmail.com
//
// tested on node 0.6.4 and express 2.5.1
//
var express = require('express'),
app = express.createServer();
app.use(express.logger());
<!DOCTYPE HTML>
<!--
/*
* Remote File Copy Demo 1.0
*
* Copyright 2012, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
<?php
// Twitter Auto-follow Script by Dave Stevens - http://davestevens.co.uk
$user = "";
$pass = "";
$term = "";
$userApiUrl = "http://twitter.com/statuses/friends.json";
@remoharsono
remoharsono / PHP ODBC - Get Table and Field Names
Last active August 13, 2018 02:55
Simple PHP script to list table names and field names when accessing MS Access database via DSN-less ODBC
<?php
// get table names
$username = 'Admin';
$password = 'blablabla';
$db = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\\xampp\htdocs\pblablabla.mdb;", $username, $password);
$result = odbc_tables($db);
echo '<div id="top">..</div><table border="1" cellpadding="5"><tr>';
@remoharsono
remoharsono / Excel VBA - Compress a file
Last active March 26, 2022 03:40
Using Excel VBA to Zip compress a file
' Add reference to:
' 1. Microsoft Scripting Runtime
' 2. Microsoft Shell Controls and Automation
' From Tools > Reference
Option Explicit
Option Base 0
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMiliseconds As Long)
@remoharsono
remoharsono / Excel VBA - Send GET Request
Created August 28, 2014 05:51
Using Excel VBA to Send HTTP GET Request to Web Server
Private Sub cmdKirimGET_Click()
Dim strResult As String
Dim objHTTP As Object
Dim URL As String
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "http://localhost/search.php"
objHTTP.Open "GET", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHTTP.send ("keyword=php")
@remoharsono
remoharsono / php_mysql_pk_dropper.php
Created October 21, 2014 06:14
PHP - MySQL Primary Key Dropper
<?php
$database_list = array('db_test_1', 'db_test_2');
echo 'Primary Key Dropper for MySQL' . "\n\n";
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
echo 'Could not connect to database server: ' . mysql_error() . "\n";
exit;