Skip to content

Instantly share code, notes, and snippets.

View fyulistian's full-sized avatar
💭
I may be slow to respond.

Fandi Yulistian fyulistian

💭
I may be slow to respond.
  • Aleph Labs
  • Centennial Tower 37th Floor Unit E Jl. Jenderal Gatot Subroto Kav. 24-25, Jakarta, Indonesia 12950
  • X @fyulistian
View GitHub Profile
@fyulistian
fyulistian / pagination.html.twig
Created March 11, 2020 08:25
Function pagination on twig
{{ _self.pagination(4, 1, 'http://127.0.0.1:8000/admin/config/system/mutual-funds?page=') }}
{% macro pagination(total, current, url, nearbyPagesLimit = 4) %}
{% spaceless %}
{% if total > 1 %}
<ul class="pagination">
{% for i in 1..total %}
{% if 0 == (current - nearbyPagesLimit) - loop.index %}
<li><a href="{{ (url ~ 1)|e }}">1</a></li>
{% if 1 != loop.index %}
// delay on typing
function delay(callback, ms) {
let timer = 0;
return function() {
let context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
callback.apply(context, args);
}, ms || 0);
};
@fyulistian
fyulistian / update.php
Last active March 25, 2019 10:53
Dynamic function for edit table DB (postgresql many to many) by PHP CI
<?php
/**
* -- Many to Many --
* [processing the reference table to communicate with the database]
* @param string $key [pk of the table] *name of primary keys
* @param string $pk [reference pk to main table] *value of primary keys
* @param array $data [data to be executed]
* @param integer $method [execution method] 0 insert, 1 update
* @return boolean [success = true]
*
@fyulistian
fyulistian / MYMenu.php
Created March 25, 2019 10:30
Recursive Menu by PHP CI and SmartAdmin (3 level max)
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MYMenu {
// private var
private $_ci;
private $_priviledges;
// constructor
function __construct() {
@fyulistian
fyulistian / buble_sort.php
Created March 25, 2019 10:25
Buble sort in php
function bubble_sort($sortarr) {
// Bubble sorting
$array_count = count($sortarr);
for($x = 0; $x < $array_count; $x++){
for($a = 0 ; $a < $array_count - 1 ; $a++){
if($a < $array_count ){
if($sortarr[$a] > $sortarr[$a + 1]) swap($sortarr, $a, $a+1);
}
}
}
@fyulistian
fyulistian / check.js
Created November 14, 2018 04:23
check the similarity between 2 values ​​in the array.
// Set Array
var idAdd = [];
// Push value to array
$('.single-box:checked').map(function () {
var vl = $(this).val();
idAdd.push(vl);
});
// check the array address have same value or not
@fyulistian
fyulistian / validate.php
Created October 24, 2018 05:50
Numeric range validator. Check the new value is available in the range or not with php.
<?php
// initialize
$range = array();
$range_price = array();
// data range
$range = array (
0 => array (
"min_range" => 10000,
"max_range" => 14000
@fyulistian
fyulistian / number-decimal.js
Created August 14, 2018 08:03
Thousand separator with decimal on typing
var element = '#numberFormattedWithDecimal';
$(element).keyup(function(event) {
/**
* Regular Expression.
* ref.
* https://regex101.com
*
* @type {RegExp}
*/
@fyulistian
fyulistian / data.js
Created July 31, 2018 09:17
Highcharts with 3 level
$(function () {
// create the chart
$('#container').highcharts({
chart: { type: 'column' }, // type charts
title: { text: '3 Level Charts' }, // title of charts
xAxis: { type: 'category' }, // x Axis
legend: { enabled: false }, // rule of legend
@fyulistian
fyulistian / check-recheck.js
Created July 26, 2018 06:04
jQuery checkbox check all, but if one not checked, primary checkbox become uncheck
// document ready
$(document).ready(function() {
// event on change
$(document).on("change","#box-all",function() {
// check all
if(this.checked) {
$(".box-single").each(function() {
this.checked = true;
})