Skip to content

Instantly share code, notes, and snippets.

View otkrsk's full-sized avatar

Nick Nuing otkrsk

  • Kuala Lumpur, Malaysia
  • 19:25 (UTC +08:00)
View GitHub Profile
@otkrsk
otkrsk / Rails DateTime Format
Last active December 16, 2015 15:49
How to format dates in Rails
%H - Hour of the day, 24-hour clock, zero-padded (00..23)
%k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
%I - Hour of the day, 12-hour clock, zero-padded (01..12)
%l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
%P - Meridian indicator, lowercase (``am'' or ``pm'')
%p - Meridian indicator, uppercase (``AM'' or ``PM'')
%M - Minute of the hour (00..59)
12:00PM = %I:%M%p
@otkrsk
otkrsk / Commit Deleted Repo Files
Last active December 17, 2015 15:39
Sometimes, files are deleted from a repo because they have become irrelevant. This is how you commit those changes for files that have been deleted.
git add -u
Additional info:
git add -A (stages All)
git add . (stages new and modified, without deleted)
git add -u (stages modified and deleted, without new)
@otkrsk
otkrsk / php_list_directory.php
Last active June 12, 2025 02:20
Some PHP code snippets to manipulate directories and files.
<?php
$source = "/path/to/your/file/";
$files = scandir("$source");
foreach($files as $file) {
// inside this loop, we strip the information from the CSV file
$arrLines = file($source . $file);
foreach($arrLines as $lines) {
// display each element
@otkrsk
otkrsk / MySQL Quickstart Snippet
Last active May 1, 2019 00:53
Quick & dirty snippet to create a MySQL database and table when I'm too lazy to type.
# Create Database
CREATE DATABASE `database_name`;
# Create Table
CREATE TABLE `table_name` (
contact_id INT(10) NOT NULL AUTO_INCREMENT,
name VARCHAR(40),
birthdate DATE,
PRIMARY KEY (contact_id)
);
@otkrsk
otkrsk / Nginx-redirect-rewrite
Last active August 29, 2015 14:02
Setup nginx to redirect www to non-www
server {
server_name www.yourdomain.com
rewrite ^(.*) http://yourdomain.com
}
@otkrsk
otkrsk / gist:266f4753d0119cfa9d93
Last active July 20, 2016 08:54
Format Date Output in Bash
# Format that we want to output: 20140813101546
date "+%Y%m%d%I%M%S"
@otkrsk
otkrsk / backup_restore_mysql_dump
Last active August 29, 2015 14:05
Backup and Restore MySQL Dump
#backup all databases in one file (eventually add the option --add-locks):
mysqldump -u [username] -p[root_password] [database_name] > file.sql
#backup all databases in one gzipped file:
mysqldump -u [username] -p[password] -–all-databases | gzip > file.sql.gz
#restore all databases:
mysql -u [username] -p[password] < file.sql
@otkrsk
otkrsk / delete_file_extension
Last active July 20, 2016 08:53
Search File by Particular File Extension and Delete
find <path> -name "*.<file_extension>" -delete
@otkrsk
otkrsk / mail_one_liner.sh
Created August 14, 2014 07:46
Send Email from Command Line with a One-Liner
mail -s "Subject goes here" [email protected] < path_to_file_with_contents.txt
#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/