Skip to content

Instantly share code, notes, and snippets.

@dertajora
dertajora / greenmiles.py
Last active August 30, 2023 06:41
Grenmiles prototype
from datetime import datetime
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
# data trip of users
# id, driverId, userId, amount, rideType, latOrigin, longOrigin, latDestination, longDestination, distance, createdAt, finishedAt
trips = [
[1,"b83c50be-4b17-405a-8885-f46b1cb12beb","0911d670-cb99-4000-9cae-c082c1c98c95", 12000, 1, -6.2812861, 107.0149711, 6.246310, 107.018128, 2.3, "2023-08-20 10:10:10", "2023-08-20 10:25:10"],
[2,"x123dda-4we7-ss5a-9985-xxeweb12beb","0911d670-cb99-4000-9cae-c082c1c98c95", 15000, 1, -6.2023535,106.8150157, -6.2273916,106.8043289, 1.5, "2023-08-20 11:10:10", "2023-08-20 11:45:10"],
[3,"d312fabd-2f65-493b-93d0-67a1a31d4e6e","0911d670-cb99-4000-9cae-c082c1c98c95", 35000, 2, -6.2273916,106.8043289, -6.2271669,106.7945101, 2.9, "2023-08-20 18:10:10", "2023-08-20 18:30:10"],
@dertajora
dertajora / fake_data.sql
Created October 21, 2021 19:15
Query to Generate Fake Dataset in Google BigQuery
-- https://medium.com/google-cloud/yet-another-way-to-generate-fake-datasets-in-bigquery-93ee87c1008f
CREATE TEMP FUNCTION entity(seed INT64)
RETURNS STRUCT<transaction_id String, user_id Integer, transaction_date String, ledger_type String, points Integer, partner String, remarks String, country String>
LANGUAGE js
AS """
var t = {};
var items = [100,150,200,250,300,350,400]
var countries = ["sg", "id"]
@dertajora
dertajora / script
Created December 27, 2018 03:13
Truncate table with foreign key limitation
truncate campaign restart identity cascade
@dertajora
dertajora / example_of_function
Created September 22, 2018 12:58
Example of beego function in controller. Created for submitting an issue
// @Title GetContestants
// @Description Get list contestant for specific campaign
// @Success 200 success
// @Param X-Tenant=>tenantID header string true "tenant id"
// @Param page query int 1 false "active page"
// @router /:campaignID/contestants [get]
func (c *AdminContestantController) GetContestants(page int, tenantID string, campaignID int) *jsonapi.JsonAPIResponse {
totalPage, err := c.contestantHandler.GetTotalPage(campaignID)
@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.
@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 / 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 / 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 / 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 / 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);