Skip to content

Instantly share code, notes, and snippets.

@Zetzumarshen
Zetzumarshen / fill.js
Last active August 7, 2017 04:24
How to fill input quickly
// tab content is parent
$.each($('.tab-content :input'),function(index, dom){
if(index % 2 == 0){
$(dom).val(index / 2);
} else {
$(dom).val("Kendala " + index /2);
}
});
@Zetzumarshen
Zetzumarshen / filterUnique.js
Created July 26, 2017 08:02
Filter unique object
for (var key in responseData) {
// unique nominal_tarif
var compareKodeMataAnggaran = null;
responseData[key] = responseData[key].filter(function(value){
if( compareKodeMataAnggaran != value.kode_mata_anggaran){
compareTarif = value.nominal_tarif;
return true;
}
});
}
@Zetzumarshen
Zetzumarshen / csvParser.hs
Created May 18, 2017 00:57
CSV Parser using parsec/haskell
import Text.ParserCombinators.Parsec
import System.IO
csvFile = endBy line eol
line = sepBy cell (char ',')
cell = many (noneOf ",\n")
eol = char '\n'
parseCSV :: String -> Either ParseError [[String]]
parseCSV input = parse csvFile "(unknown)" input
@Zetzumarshen
Zetzumarshen / split_sorted.php
Created April 5, 2017 02:39
split array if previous element is not same
function split_sorted()
{
$arr = array('1','2','2','3');
$output = array();
$previous = null;
$temp = array();
foreach($arr as $row){
if(isset($previous) === true and $previous !== $row){
$output[] = $temp;
@Zetzumarshen
Zetzumarshen / carFactory.php
Last active May 18, 2016 23:46
PHP Gotcha: Factory Pattern
class carFactory
{
public function createObject($carClass)
{
$file = $carClass . '.php';
require_once $file;
$obj = new $carClass; // magic
return $obj
}
@Zetzumarshen
Zetzumarshen / formMagic.php
Created May 18, 2016 01:12
gotcha: automatically creates an array from name tag shenanigans
<form method="post" action="form.php">
<input name="person[male][first_name]" value="john" />
<input name="person[male][last_name]" value="smith" />
<input name="person[female][first_name]" value="jane" />
<input name="person[female][last_name]" value="jones" />
<input type="submit" value="Submit">
</form>
<?php
// Testingclass untuk User.php
// pakai TestCase karena gw pakai kenjis testing framework
Class User_test extends TestCase
{
public function test_mockUsername(){
// secara implisit, melakukan mock ke method getPost()
// sekarang getPost() akan return NULL
$model = $this->getMockBuilder('Users')
->setMethods(array('getUsername'))
->getMock();
// Contoh mocking dengan membaca global variable.
// Buatlah fungsi private/protected untuk di mock di phpunit
class User
{
public function getUsername(){
return $this->getPost();
}
protected function getPost(){
return $username = $_POST['username'];
$(document).ready(function(){
// datatables init
var table = $('#example').DataTable();
// global variable
document.inputLock = false;
$('#example tbody').on('click', 'td', function () {
<?php
class GenericTree {
public $root;
function __construct() {
$this->root = new Node();
}