Skip to content

Instantly share code, notes, and snippets.

View ombak's full-sized avatar
🏠
Working from home

Sukma Saputra ombak

🏠
Working from home
View GitHub Profile
View bagaimana_melakukan_print_console_pada_pytest.sh
# gunakan saat pytest error
pytest --capture=sys
# gunakan saat pytest success
pytest -s
View Selection_Sort_dng_Python_1.py
def selection_sort(mylist):
# i indicates how many items were sorted
for i in range(len(mylist)-1):
# To find the minimum value of the unsorted segment
# we first assume that the first element is the lowest
min_index = i
# We then use j to loop through the remaining elements
dex = 0
for j in range(i+1, len(mylist)):
if mylist[j] < mylist[min_index]:
View fungsi_php_range_2.php
<?php
//...dengan menggunakan step akan menghasilkan kelipatan 10
//...yang dimulai dari 0 dan diakhiri di nilai 100
//...array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
foreach (range(0, 100, 10) as $number) {
echo $number;
}
View fungsi_php_range_1.php
<?php
//...array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
foreach (range(0, 12) as $number) {
echo $number;
}
View menghubungkan_php_dng_mysql_2.php
<?php
//...kosongkan parameter password bila tidak ada password
$conn = mysql_connect("localhost", "root", "");
//...bila koneksi gagal
if(!$conn) {
die("koneksi gagal, periksa lagi parameter.");
}
//...mysql_error() untuk menampilkan pesan error
View menghubungkan_php_dng_mysql_1.php
<?php
//...kosongkan parameter password bila tidak ada password
$conn = mysql_connect("localhost", "root", "");
//...bila koneksi gagal
if(!$conn) {
die("koneksi gagal, periksa lagi parameter.");
} else {
echo "koneksi berhasil.";
}
View enable_short_tags_4.php
<?php
echo 'Welcome '.($user['is_logged_in'] ? $user['first_name'] : 'Guest').'!';
View enable_short_tags_3.php
<?php
//....basic true/false declaration
$user_id = (!empty($id) ? $id : '');
View enable_short_tags_2.php
<?php
if ( $kondisi ) {
print 'statement';
} else {
print 'other statement';
}