Skip to content

Instantly share code, notes, and snippets.

View dungdt88's full-sized avatar

Richard Dam dungdt88

  • Ho Chi Minh City, Vietnam
View GitHub Profile
@dungdt88
dungdt88 / setfacl_sample.sh
Last active December 16, 2015 16:49
Share permission between user & apache
setfacl -R -m u:apache:rwX -m u:`whoami`:rwX app/cache app/logs
setfacl -dR -m u:apache:rwx -m u:`whoami`:rwx app/cache app/logs
@dungdt88
dungdt88 / gist:5465626
Last active December 16, 2015 16:49
Convert name to slug
<?php
function name2Slug($name, $separator = '-', $maxLength = 40)
{
$url = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $name);
$url = trim(substr(strtolower($url), 0, $maxLength));
$url = preg_replace('/[^a-z0-9-]/', '-', $url);
$url = preg_replace('/'.$separator.'+/', '-', $url);
return $url;
}
@dungdt88
dungdt88 / gist:bcade6070dd7133a815c
Last active August 29, 2015 14:10
Graph generation with fixed degree
insufficient[degs_, edgelist_, donelist_] := Catch[Module[
{j, k, n = Length[degs], diff},
For[j = 1; j <= n, j++,
If[degs[[j]] == 0, Continue[]];
diff = degs[[j]] - Length[Union[donelist, edgelist[[j]]]];
If[diff <= 0, Throw[True]];
];
False
]]
@dungdt88
dungdt88 / ssh_with_public_key.sh
Last active March 7, 2016 06:15
SSH with Public Key
# On Client
## Generate Key
ssh-keygen -t rsa {-b 4096}
## Copy identity to remote-host (requires remoteuser's password)
ssh-copy-id -i <path/to/public/key> <remoteuser>@<remotehost>
## or just copy the content of file ~/.ssh/id_rsa.pub on Client to the end of file ~/.ssh/authorized_keys on Server
## SSH
import java.util.Random;
public class HelloWorld {
public static void main(String[] args) {
System.out.println(randomString(-229985452) + " " + randomString(-147909649));
}
public static String randomString(int i) {
Random ran = new Random(i);
StringBuilder sb = new StringBuilder();
@dungdt88
dungdt88 / remove_mysql.sh
Created December 10, 2015 03:07
Completely remove MySQL in Ubuntu
sudo service mysql stop #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.5
sudo apt-get purge mysql-client-core-5.5
@dungdt88
dungdt88 / mysql_utf8mb4.sql
Created December 17, 2015 09:53
Convert UTF8 to UTF8mb4 in MySQL to support utf8 4 bytes
ALTER TABLE `{some_table}` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `{some_table}` CHANGE COLUMN `{some_column}` `{some_column}` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL;
## Add openjdk PPA
sudo add-apt-repository ppa:openjdk-r/ppa
## Update the repo
sudo apt-get update
## Install openjdk-8-jdk
sudo apt-get install openjdk-8-jdk
## Set the default Java
## Remove all stopped containers
docker rm $(docker ps -a -q)
## Remove images with <none> tag
docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
## Stats of all containers
docker stats $(docker ps | awk '{if(NR>1) print $NF}')
## Allow a user to use docker
@dungdt88
dungdt88 / change_docker0.md
Last active April 20, 2016 07:21
Change docker0

In this guide, you will learn how to change the default docker bridge network's subnet to 10.11.12.0/24 on Ubuntu

Docker-engine's default options

Docker creates a bridge called docker0 with a default ip address of 172.17.0.1.

On Ubuntu the configuration file is located at:

/etc/default/docker