Skip to content

Instantly share code, notes, and snippets.

View fajarwz's full-sized avatar
👨‍💻
Working from anywhere

Fajar Windhu Zulfikar fajarwz

👨‍💻
Working from anywhere
View GitHub Profile
@fajarwz
fajarwz / binarySearch.php
Created November 19, 2023 06:51
search for a value in a sorted array using Binary Search, the best searching algorithm for a sorted array
<?php
function binarySearch($arr, $target) {
$left = 0;
$right = count($arr) - 1;
while ($left <= $right) {
$mid = floor(($left + $right) / 2);
// Check if the target is present at the middle
@fajarwz
fajarwz / README.md
Created October 13, 2023 03:34
notes for CD with Github Actions

How to create CD with Github Actions

  • using appleboy/ssh-action@master for cd
  • see cd.yml for the yml example
  • make sure the SSH_KEY is correct. Use the SSH private key. create SSH key in your server and copy the private key to Github Secrets
  • make sure to write your public key to authorized keys in server. you can use this command to do that: cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
  • make sure that the server dont ask password while we git pulling it manually. Use this command: "git config credential.helper store" or "git config --global credential.helper store" to store the git credential in cache. after we once again pulling the repo in the server, the git cache our credential. with that when github actions try to pull the repo automatically, it doesnt need to write credentials
@fajarwz
fajarwz / simple-nginx.conf
Created October 2, 2023 02:30
Simple Nginx Configuration
server {
listen 80;
# server_name _;
root /var/www/laracuss/public; # project-name/public
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
@fajarwz
fajarwz / toPascalCase.php
Created July 14, 2022 15:07
Solution for a "Convert words to PascalCase" challenge
<?php
// For example: if str is "BOB loves-coding" then your program should return the string bobLovesCoding.
function toPascalCase($str) {
$separators = [' ', '-', '%', '*'];
$separatorsInString = implode('', $separators);
return str_replace($separators, '', ucwords(strtolower($str), $separatorsInString));
}
<?php
// https://coderbyte.com/algorithm/stock-maximum-profit
function StockPicker($arr) {
$buyPrice = 0;
$sellPrice = 0;
$maxProfit = -1;
$changeBuyIndex = true;
@fajarwz
fajarwz / helpers.php
Last active July 2, 2022 07:07
API Response for PHP / Laravel with meta properties
<?php
// app/helpers.php in Laravel
// add this file to "files" in composer.json
// "autoload": {
// "psr-4": {
// ...
// },
// "files": [
// "app/helpers.php"
@fajarwz
fajarwz / min_dice_flip_count.php
Created February 21, 2022 16:08
get minimum dice flip count
<?php
function flip_count($arr) {
$flip_count;
$min_flip_count = 9999999;
foreach ($arr as $value) {
$flip_count = 0;
foreach ($arr as $value2) {
if ($value == $value2) {
@fajarwz
fajarwz / opposite_dice_problem.php
Created February 21, 2022 15:55
get the opposite number of a dice
<?php
// dice problem
function get_the_opposite($n) {
return 7 - $n;
}
echo get_the_opposite(3);
@fajarwz
fajarwz / install-laravel-swoole
Last active December 22, 2023 15:50
install laravel swoole on Ubuntu 21.04
# using Ubuntu
# install laravel first
laravel new my-app
# get laravel octane package
composer require laravel/octane
# maybe you encountering an error such as "require ext-curl". You can install it with this command
sudo apt-get install php-curl
# then install it again using "composer require laravel/octane"
@fajarwz
fajarwz / animal.php
Created July 5, 2021 13:54
PHP OOP example. Create class, object, get-set attribute
<?php
class animal {
public $name;
public $foot;
function setName($name) {
$this->name = $name;
}