This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
def cek(string): | |
if len(string) >= 2: | |
dupe = 0 | |
for i in Counter(string).most_common(): | |
if i[1] >= 2: dupe += 1 | |
if dupe >= 2: return True | |
return False | |
print cek('aaabbcdeg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Terbilang | |
{ | |
public static function generate($angka) { | |
$angka = (float)$angka; | |
$bilangan = array( | |
'', | |
'satu', | |
'dua', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function insert($table, $fields, $data) | |
{ | |
$SQL = "INSERT INTO {$table} (".implode(', ', $fields).") VALUES (".implode(', ', array_intersect_key($data, array_flip($fields))).")"; | |
echo $SQL; | |
// lanjutkan peng-query-an disini | |
} | |
insert('mahasiswa', array('nim', 'nama', 'jk'), array('nim'=>'1088', 'nama'=>'andi', 'jk'=>'l', 'alamat'=>'jln.sendok')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// protected/controllers/MahasiswaController.php | |
public function actionAbsen(){ | |
$dataProvider = new CActiveDataProvider('Kehadiran', array( | |
'criteria'=>array( | |
'condition'=>'nim='.Yii::app()->user->name, | |
'with'=>array('pertemuan'), | |
), | |
)); | |
$this->render('absen', array( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Db | |
{ | |
private $conn = null; | |
private $dsn; | |
private $user; | |
private $password; | |
public function __construct($dsn, $user, $password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'Db.php'; | |
require 'Paging.php'; | |
require 'Table.php'; | |
$db = new Db('localhost', 'root', '', 'sakila'); // membuat koneksi | |
$page = isset($_GET['page']) ? $_GET['page'] : 1; // mengecek halaman paging | |
$actors = new Paging($db, 'actor', $page); // membuat objek paging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Table | |
{ | |
private $result; | |
private $header; | |
private $offset; | |
public function __construct($result, $header, $offset = 1) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Paging | |
{ | |
private $conn; | |
private $table; | |
public $limit = 10; | |
public $offset = 0; | |
public $total = 0; | |
public $total_page = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Db | |
{ | |
private $conn; | |
private $query; | |
private $result; | |
public function __construct($host, $username, $password, $db_name) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$operand1 = $_POST['operand1']; | |
$operand2 = $_POST['operand2']; | |
$operator = $_POST['operator']; | |
eval("\$result = $operand1 $operator $operand2;"); | |
echo json_encode(array('result'=>$result)); |