Skip to content

Instantly share code, notes, and snippets.

View otkrsk's full-sized avatar

Nick Nuing otkrsk

  • Kuala Lumpur, Malaysia
  • 16:47 (UTC +08:00)
View GitHub Profile
@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.
@otkrsk
otkrsk / Sum a MySQL COUNT Query
Created March 5, 2013 06:47
Sum a MySQL COUNT query
SELECT SUM(A.COUNT)
FROM
(SELECT COUNT(*) AS count FROM table1
union all
SELECT COUNT(*) AS count FROM table2) A
@otkrsk
otkrsk / Responsive CSS
Created March 25, 2013 09:58
Remove certain DIVs when viewing on a mobile device.
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
.qrcode widget {
display: none
}
@media screen and (min-width: 0px) and (max-width: 400px) {
#my-content { display: block; } /* show it on small screens */
}
@otkrsk
otkrsk / Postgres Backup & Restore
Last active July 20, 2016 08:52
Postgres Backup & Restore
# Backup
pg_dump -U username database_to_backup -f /path/to/backup/file
#Restore
psql -U username -d database_to_restore -f /path/to/backup/file