Skip to content

Instantly share code, notes, and snippets.

@dertajora
dertajora / save_to_csv.php
Last active May 7, 2021 00:38
This script is used to generate CSV file and save it to specific folder, I implement it on Codeigniter. Please modify the location of APPPATH section if you want to save to another location
<?php
// this script would save csv file to this specified directory
// APPPATH is location of application folder in Codeigniter
$file = fopen(APPPATH . '/../upload/'.'tesaasasat.csv', 'wb');
// set the column headers
fputcsv($file, array('Column 1', 'Column 2', 'Column 3', 'Column 4', 'Column 5'));
// Sample data. This can be fetched from mysql too
$data = array(
@dertajora
dertajora / BCA_API.php
Last active January 4, 2024 04:00
This is my code when learn to use BCA API for my office. This code only works on Sandbox environment and there is no confidential information here. FYI, based on my experience if you want to implement this code using real environment of BCA API, you need to do some UAT with BCA side.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class BCAAPI extends MY_Controller {
function __construct(){
$this->api_key = "YOUR API KEY";
$this->api_secret = "YOUR API SECRET";
$this->client_id = "YOUR CLIENT ID";
@dertajora
dertajora / decode_unicode_google_maps_api.php
Last active February 25, 2020 23:03
Decode Encoded Unicode string (field html-instruction) on Google Maps API response
<?php
// Lets say , we want to send a direction request with guidance to Google Maps API using link below.
// https://maps.googleapis.com/maps/api/directions/json?origin=-6.190109,%20106.798565&destination=-6.177596,%20106.792611&key=USEYOUR_KEY
// some of request, especially in field html-instruction would return unicode html text like this one ('Head \u003cb\u003ewest\u003c/b\u003e').
// for some reason, I just want to use the text provided there ('Head west').
// after some googling and asking, here is the best code I have (right now)
# example response
//Type A : There are 2 sentence in one single direction response
@dertajora
dertajora / some_script.bat
Last active July 17, 2017 11:22
Batch File I have Played with. Close all opened specified program. Delete temporary file with specific file
rem Close all cmd.exe
taskkill /F /IM cmd.exe /T
rem Delete temporary folder that contain "scope" in its name
FOR /D /R %dir% %%X IN (scope*) DO RMDIR /S /Q "%%X"
@dertajora
dertajora / rounding_to_nearest.php
Created August 1, 2017 07:24
Rounding number to nearest multiple number you want
<?php
function round_up_to_nearest_n($int, $n) {
return ceil($int / $n) * $n;
}
//result will be 10100
round_up_to_nearest(10001,100);
//result will be 100000
round_up_to_nearest(85000,50000);
@dertajora
dertajora / query_to_db_access.php
Last active October 3, 2017 10:28
How to query to MS DB Access using PHP. #This script is used to do query in MS DB Access in PHP. I use it on little project when I'm working as Web Developer in Garena to build an automation system for specific task
<?php
#October 3, 2017
#First activate pdo_odbc in your server
#extension=php_pdo_odbc.dll
#then
#odbc.defaultbinmode=1
#odbc.defaultlrl=4096
#odbc.max_links=-1
@dertajora
dertajora / manual_logging.php
Created October 4, 2017 05:13
Manual logging using txt file in PHP
#1
$file = fopen('log_script.txt', 'a');
fwrite($file, $error. "\n");
fclose($file);
#2
$file_log = 'log_script.txt';
file_put_contents($file_log, $error."\n", FILE_APPEND | LOCK_EX);
@dertajora
dertajora / upload_via_ftp.php
Created October 5, 2017 09:33
Upload file Via FTP using PHP
// FTP access parameters
$host = 'xxx';
$usr = 'xxx';
$pwd = 'xxx';
// file to move:
// $local_file = 'D:/xampp/htdocs/absen_folder/log_script.txt';
// $local_file = 'D:\xampp\htdocs\absen_folder\log_script.txt';
$local_file = 'cek.txt';
$ftp_path = 'derta.co.id/htdocs/tes_derta/'.date('Y-m-d').'/cek.txt';
@dertajora
dertajora / 2018_01_27_021848_create_table_users.php
Last active December 17, 2018 11:03
Example of generated migration file when we want to create a table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTableUsers extends Migration
{
/**
* Run the migrations.
@dertajora
dertajora / 2018_01_26_113346_adjust_tickets_table.php
Last active January 27, 2018 06:46
Example of generated migration file when we want to modify a table
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AdjustTicketsTable extends Migration
{
/**
* Run the migrations.