Skip to content

Instantly share code, notes, and snippets.

View otkrsk's full-sized avatar

Nick Nuing otkrsk

  • Kuala Lumpur, Malaysia
  • 20:35 (UTC +08:00)
View GitHub Profile
@otkrsk
otkrsk / nano_commands.md
Last active September 7, 2016 06:22
Nano Commands

Ctrl + K is used to Cut a line.

Alt + ^ is used to Copy it.

Ctrl + U is used to paste them.

@otkrsk
otkrsk / do_mongo.sh
Last active September 5, 2016 16:00
Snippet to set up DO Droplet with MongoDB
#cloud-config
apt_sources:
# Enable MongoDB repository
- source: deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse
keyid: 7F0CEB10
filename: mongodb.list
apt_update: true
packages:
- mongodb-org
@otkrsk
otkrsk / get_extension.php
Created September 5, 2016 10:53
Get a file's name or extension (or any other part)
<?php
$name = pathinfo($file, PATHINFO_FILENAME); // returns filename
$ext = pathinfo($file, PATHINFO_EXTENSION); // returns extension
@otkrsk
otkrsk / html_safe_mysql.php
Last active August 10, 2016 04:29
Preserve HTML tags and formatting into a MySQL database.
$str = "I 'am' a <strong>monster</strong>!";
// This will preserve the HTML tags (as well as the quotes) and make it safe to save into MySQL.
echo htmlentities($str, ENT_QUOTES);
// To display it with all its HTML glory, use html_entity_decode().
echo html_entity_decode($str);
@otkrsk
otkrsk / check_last_element.php
Created August 4, 2016 04:42
A snippet of how to check for the last element of the array and perform actions on to it.
/**
* Check if the current array element is the last one, if it is, do something.
*/
$array = array('a' => 1,'b' => 2,'c' => 3);
$lastElement = end($array);
foreach($array as $k => $v) {
echo $v . '<br/>';
if($v == $lastElement) {
// This is the last element. Do as you please.
@otkrsk
otkrsk / download_remote_directory.md
Last active July 26, 2016 04:40
Sometimes you don't have SSH access to a server, or your FTP client is misbehaving (i.e., connects but can't list the directories) and you need to download a whole directory, you can use the following in your terminal.

From the terminal, fire this up:

wget -r ftp://user:[email protected]/<path to your directory>

If you've some special characters in the credentials, you can specify the --user and --password arguments to get it to work.

Example with custom login with specific characters:

wget -r --user="user@login" --password="Pa$$wo|^D" ftp://server.com/<path to your directory>

@otkrsk
otkrsk / gitlab_keys.md
Last active July 26, 2016 02:22
Generate SSH keys on your server so that you can pull from your repository without using passwords.
cd ~/.ssh
ssh-keygen -t rsa

enter gitlab_rsa leave password empty

cat ~/.ssh/gitlab_rsa.pub

@otkrsk
otkrsk / scandir_and_sort.php
Created July 20, 2016 08:59
Scan a directory and sort the files according to the last modified date.
<?php
function scan_dir($dir) {
$ignored = array('.', '..', '.svn', '.htaccess');
$files = array();
foreach (scandir($dir) as $file) {
if (in_array($file, $ignored)) continue;
$files[$file] = filemtime($dir . '/' . $file);
}
@otkrsk
otkrsk / vsftpd_setup.md
Last active July 14, 2016 05:17
Gist to set up and configure vsftpd on Ubuntu

Run:

sudo apt-get install vsftpd

Edit /etc/vsftpd.conf

Disable anonymous login

anonymous_enable = NO
#Mounting the share is a 2 stage process:
# 1. Create a directory that will be the mount point
# 2. Mount the share to that directory
#Create the mount point:
mkdir share_name
#Mount the share (edited for Mac OS X):
#The -t flag is to indicate the file system type. In this case, it is smbfs.
mount -t smbfs //username:[email protected]/share_name share_name/