Skip to content

Instantly share code, notes, and snippets.

Avatar

Muhamad Fajar heyost

View GitHub Profile
@heyost
heyost / urls.py
Created Aug 23, 2017
Django favicon
View urls.py
# 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),
@heyost
heyost / atom-check.sh
Created Jul 26, 2017
Simple script to check new version of Atom on Fedora
View atom-check.sh
#!/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 / README.md
Created Mar 17, 2017
Simple script to change httpd/apache configuration file
View README.md

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 / pip_update.sh
Created Mar 9, 2017
Update all Python PIP
View pip_update.sh
#!/bin/bash
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 sudo pip install -U
View Powerline show Git branch.sh
mkdir -p ~/.config/powerline
cat <<-'EOF' > ~/.config/powerline/config.json
{
"ext": {
"shell": {
"theme": "default_leftonly"
}
}
}
EOF
@heyost
heyost / server.sh
Created Sep 17, 2016
simple php server, like "php artisan serve"
View server.sh
#!/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
@heyost
heyost / httpd-vhosts.conf
Last active Apr 29, 2022
Create dynamic Laravel project vhost on Arch Linux
View httpd-vhosts.conf
# Custom vhost laravel wildcard
# enable vhost_alias_module first on httpd.conf
<VirtualHost *:80>
ServerAdmin webmaster@laravel.dev
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 / clickable_url.php
Created Jun 30, 2016
Regex clickable URL from plain string
View clickable_url.php
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
View get_past_1_week_and_1_week_present_on_MySQL.sql
# 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 / polymer-import.php
Last active Dec 18, 2015
Simple polymer custom elements import using PHP
View polymer-import.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];