Skip to content

Instantly share code, notes, and snippets.

View heyost's full-sized avatar

Muhamad Fajar heyost

View GitHub Profile
@heyost
heyost / polymer-import.php
Last active December 18, 2015 03:14
Simple polymer custom elements import using PHP
<?php
$list = ['custom_elements_folder1', 'custom_elements_folder2'];
$num = 0;
for($num; $num < count($list); $num++){
$dir = glob($list[$num] . '/*');
foreach ($dir as $file) {
if(is_file($file) && strpos($file, '.html')){
echo "<link rel=\"import\" href=\"" . $file . "\">\n";
} else{
echo $file[0];
@heyost
heyost / get_past_1_week_and_1_week_present_on_MySQL.sql
Created April 2, 2016 08:51
Get some week between date in MySQL
# 1 week past
SELECT DATE_ADD("2016-02-04", INTERVAL(-6-DAYOFWEEK("2016-02-04")) DAY) AS start, DATE_ADD("2016-02-04", INTERVAL(0-DAYOFWEEK("2016-02-04")) DAY) AS FINISH
# present week
SELECT DATE_ADD("2016-02-04", INTERVAL(1-DAYOFWEEK("2016-02-04")) DAY) AS start, DATE_ADD("2016-02-04", INTERVAL(7-DAYOFWEEK("2016-02-04")) DAY) AS FINISH
@heyost
heyost / clickable_url.php
Created June 30, 2016 08:06
Regex clickable URL from plain string
function clickable_url($plain_text)
{
// check all url with http:// pattern
$pattern_http = '~([^<>]*>)(*SKIP)(*F)|'; // skip url check if inside html tag
$pattern_http .= '([-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z])(*SKIP)(*F)|'; // skip email pattern
$pattern_http .= '(?:(?:ht|f)tps?://)'; // find url with http | https | ftp | ftps
$pattern_http .= '[\w-]+'; // host name
$pattern_http .= '(?:\.[\w-]+)+'; // domain name
$pattern_http .= '[\w-.,@?^=%&:/\~+#!]*[\w-@?^=%&/\~+#]~xiuS'; // path name
@heyost
heyost / httpd-vhosts.conf
Last active April 29, 2022 13:37
Create dynamic Laravel project vhost on Arch Linux
# Custom vhost laravel wildcard
# enable vhost_alias_module first on httpd.conf
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName laravel.dev
ServerAlias *.laravel.dev
# This will be the wildcarded document root. Any folder you create in /srv/http/php/laravel/* will be automatically a subdomain name.
VirtualDocumentRoot /srv/http/php/laravel/%-3/public
@heyost
heyost / server.sh
Created September 17, 2016 03:02
simple php server, like "php artisan serve"
#!/bin/bash
# simple php server, like "php artisan serve"
# put this file 1 folder behind root directory
# e.g. this file on folder "project"
# and inside "project" folder have 1 folder contain codeigniter project,
# so root folder is name of folder with contain project
echo "Type root directory, followed by [ENTER]:"
read root
mkdir -p ~/.config/powerline
cat <<-'EOF' > ~/.config/powerline/config.json
{
"ext": {
"shell": {
"theme": "default_leftonly"
}
}
}
EOF
@heyost
heyost / pip_update.sh
Created March 9, 2017 15:03
Update all Python PIP
#!/bin/bash
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip install -U
@heyost
heyost / README.md
Created March 17, 2017 03:45
Simple script to change httpd/apache configuration file

First run this outside script sudo cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.bak.conf

Make sure, you have 2 php version installed on computer, and create 2 configuration httpd/apache file to easy change php version

After script created, save on home and use bashrc to create alias e.g. alias switch-php=". ~/Script/switch_php.sh" put on last line, restart bash, and excute switch-php 7 to change php to version 7, and switch-php 56 to change to php version 56

@heyost
heyost / atom-check.sh
Created July 26, 2017 15:42
Simple script to check new version of Atom on Fedora
#!/bin/bash
# source - https://fedoraproject.org/wiki/Atom
ATOM_INSTALLED_VERSION=$(rpm -qi atom | grep "Version" | cut -d ':' -f 2 | cut -d ' '$
ATOM_LATEST_VERSION=$(curl -sL "https://api.github.com/repos/atom/atom/releases/latest$
echo Installed version: $ATOM_INSTALLED_VERSION
echo Latest version: $ATOM_LATEST_VERSION
echo ------------------------------------
if [[ $ATOM_INSTALLED_VERSION < $ATOM_LATEST_VERSION ]]; then
@heyost
heyost / urls.py
Created August 23, 2017 09:58
Django favicon
# example using favicon on Django Admin
from django.conf.urls import url
from django.contrib import admin
from django.views.generic import RedirectView
from muhfajar.settings import STATIC_URL
urlpatterns = [
url(r'^favicon\.ico$', RedirectView.as_view(url=STATIC_URL + 'path_to_favicon.ico')),
url(r'^', admin.site.urls),