Skip to content

Instantly share code, notes, and snippets.

View otkrsk's full-sized avatar

Nick Nuing otkrsk

  • Kuala Lumpur, Malaysia
  • 21:47 (UTC +08:00)
View GitHub Profile
@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 / 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 / mail_one_liner.sh
Created August 14, 2014 07:46
Send Email from Command Line with a One-Liner
mail -s "Subject goes here" yourname@email.com < path_to_file_with_contents.txt
@otkrsk
otkrsk / gist:3779957
Created September 25, 2012 04:18
Connecting to a database from classic ASP
Dim conn
Dim objRS
Dim cmd
Set conn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
Set cmd = Server.CreateObject("ADODB.Command")
conn.Open "Provider=SQLOLEDB;Data Source=192.168.x.x;Initial Catalog=xxxxx;User Id=x;Password=xxxxxxxxxxxxxx"
@otkrsk
otkrsk / gist:4103164
Created November 18, 2012 02:58
Rails Console
# Find an object in the console
User.where("query = ?", condition)
# Find an attribute in the model (if it is an array)
u.first.attribute
# Destroy an object that has association. Better than delete.
object.destroy
# Pretty output
@otkrsk
otkrsk / MySQL Query for Duplicates
Last active December 14, 2015 05:39
Query to check for Duplicates in a MySQL database.
SELECT * FROM `table_name`
WHERE `record_name` IN (
SELECT `record_name`
FROM `table_name`
GROUP BY `record_name`
HAVING count(`record_name`) > 1
)
ORDER BY `record_name`
@otkrsk
otkrsk / Enable Hirb in Rails Console
Created February 26, 2013 14:56
How to enable Hirb in your console.
require 'hirb'
Hirb.enable
Hirb::View.enable
@otkrsk
otkrsk / Multiline Commenting in Vim
Created March 1, 2013 03:20
Selecting and commenting multiple lines in Vim
1. Go to start of block.
2. `Ctrl+V`, then traverse down the block. Only the beginning of the line will be selected.
3. `Shift+I` to insert text at the beginning of the marker.
4. Press the hash/pound key (`#`), then escape (`Ctrl+[`). Your block of code will magically be commented.
@otkrsk
otkrsk / Pretty output with YAML on the Rails console
Created March 1, 2013 03:21
Pretty output with YAML on the Rails console.
YAML::ENGINE.yamler='syck'
@otkrsk
otkrsk / Pipe SQL Query Output to a Text File
Last active December 14, 2015 10:49
Pipe the output of a SQL query to a text file.
PostgreSQL
----------
After logging in to the PSQL console:
db=> \o /path/to/where/you/want/the/file/saved
db=> the sql query
db=>
Output is saved, though there is no feedback from the console.