Skip to content

Instantly share code, notes, and snippets.

View onpaws's full-sized avatar
🚴‍♂️
building things

Pat onpaws

🚴‍♂️
building things
View GitHub Profile
@onpaws
onpaws / ruby_fiddle.rb
Created June 14, 2012 16:04 — forked from anonymous/ruby_fiddle.rb
testing activegist
# Your Assignment:
# (easy) First, print the numbers 1 to 10 in the console
puts "1. ---------------"
(1..10).each do |i|
puts i
end
# (medium) Second, Write a method that takes an array [-4,-76, 64, 200, -2, 644] and only prints positive integers
@onpaws
onpaws / gist:4999562
Created February 20, 2013 20:59
Ruby .split() while keeping the key in the returned array. in this case the key is a period '.'
page.css('p').text.split(/(.)/).each_slice(2).map(&:join)
@onpaws
onpaws / gist:5085327
Last active December 14, 2015 12:19
MySQL snippets 2.weeks.ago in MySQL, view consumed and available space
select DATE_SUB(curdate(), INTERVAL 2 WEEK)
-- Space consumed by databases
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema;
-- Free space available
SELECT table_schema "Database Name", sum( data_length + index_length ) / 1024 / 1024 "Database Size in MB", sum( data_free )/ 1024 / 1024 "Free Space in MB" FROM information_schema.TABLES GROUP BY table_schema;
@onpaws
onpaws / gist:5678451
Created May 30, 2013 14:49
SQL Server - querying schema
select * from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME like '%Datasource%'
@onpaws
onpaws / gist:5717506
Last active December 18, 2015 03:19
Search across tables SQL Server
SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE'%cliff%'
@onpaws
onpaws / database2seeds.rb
Created February 13, 2014 01:39
Rake task to dump current Rails database into seeds.rb format
namespace :export do
desc "Prints Country.all in a seeds.rb way."
task :seeds_format => :environment do
Country.order(:id).all.each do |country|
puts "Country.create(#{country.serializable_hash.delete_if {|key, value| ['created_at','updated_at','id'].include?(key)}.to_s.gsub(/[{}]/,'')})"
end
end
end
#via http://xyzpub.com/en/ruby-on-rails/3.2/seed_rb.html
@onpaws
onpaws / bash-template.sh
Created April 16, 2014 20:04
bash: start here
#!/bin/bash
set -o nounset
set -o errexit
<<COMMENT
via http://robertmuth.blogspot.com/2012/08/better-bash-scripting-in-15-minutes.html
To perform a syntax check/dry run of your bash script run:
bash -n myscript.sh
@onpaws
onpaws / gist:2b40f25e67fb98d60bec
Created June 2, 2014 21:53
find in page with regex (JS)
var p=/.*(regu).+?\ /gi; console.log( document.body.innerText.match(p) );
@onpaws
onpaws / loadCSVfromSQL
Created October 2, 2014 16:37
Load CSV from SQL
LOAD DATA INFILE '/tmp/stats-2014.csv'
INTO TABLE orig_stats
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES ;
@onpaws
onpaws / list_perms.sql
Last active June 15, 2023 18:41
list permissions SQL Server
/* via http://stackoverflow.com/questions/7048839/sql-server-query-to-find-all-permissions-access-for-all-users-in-a-database
Security Audit Report
1) List all access provisioned to a sql user or windows user/group directly
2) List all access provisioned to a sql user or windows user/group through a database or application role
3) List all access provisioned to the public role
Columns Returned:
UserName : SQL or Windows/Active Directory user cccount. This could also be an Active Directory group.
UserType : Value will be either 'SQL User' or 'Windows User'. This reflects the type of user defined for the
SQL Server user account.