Skip to content

Instantly share code, notes, and snippets.

@belsrc
belsrc / gist:70548d021d15a8e397de
Created October 5, 2014 21:04
Download Site for offline use
# -p get all images, etc. needed to display HTML page.
# --mirror turns on recursion and time-stamping, sets infinite
# recursion depth and keeps FTP directory listings
# --html-extension save HTML docs with .html extensions
# --convert-links make links in downloaded HTML point to local files.
wget --mirror -p --html-extension --convert-links www.example.com
@belsrc
belsrc / gist:4137754
Created November 23, 2012 23:55
Measuring container height before collapsing - C#
private void Window_Loaded( object sender, RoutedEventArgs e ) {
container.Measure( new Size( Double.PositiveInfinity, Double.PositiveInfinity ) );
this._containHeight = container.DesiredSize.Height;
container.Height = 0;
}
@belsrc
belsrc / gist:4141280
Last active October 13, 2015 04:47
Send SMTP Mail - C#
private void SendEmail(string from, IEnumerable<string> to, string subj, string body, bool isHtml = false, SmtpClient client) {
MailMessage message = new MailMessage();
message.From = new MailAddress( from );
foreach( string copy in cc ) {
message.To.Add( new MailAddress( copy ));
}
message.Subject = subj;
message.Body = body;
message.IsBodyHtml = isHtml;
@belsrc
belsrc / gist:4715772
Last active December 12, 2015 04:38
WPF Gravatar Image Binding
using Cgum; // Common methods - EncryptMd5() [personal library]
// init: Gravatar = GetAvatar( email )
public static readonly DependencyProperty GravatarProperty =
DependencyProperty.Register( "Gravatar",
typeof( BitmapImage ),
typeof( SingleCustomerVM ),
new PropertyMetadata(
new BitmapImage()
@belsrc
belsrc / gist:4715782
Last active December 12, 2015 04:38
Find duplicate items in multiple lists
List<List<string>> lists = new List<List<string>>() {
new List<string> {"Hello", "World", "7"},
new List<string> {"Hello", "7", "Person"},
new List<string> {"7", "7", "Hello"}
};
List<string> common = lists.Cast<IEnumerable<string>>(
.Aggregate( ( a, b ) => a.Intersect( b ) )
.ToList();
@belsrc
belsrc / gist:4997411
Created February 20, 2013 17:42
IEnumerable String Replace
var list = list.Select( s => s.Replace( toReplace, replace ) ).ToArray();
@belsrc
belsrc / gist:5178977
Created March 17, 2013 00:27
ADO.Net GetData
private DataTable GetData( string conString, string table ) {
DataTable dt = new DataTable();
using( SqlConnection sqlConn = new SqlConnection( conString ) ) {
sqlConn.Open();
using( SqlCommand sqlCmd = new SqlCommand( "SELECT * FROM " + table, sqlConn ) ) {
using( SqlDataAdapter sqlDa = new SqlDataAdapter( sqlCmd ) ) {
sqlDa.Fill( dt );
}
}
@belsrc
belsrc / letter_count.sql
Created January 12, 2016 15:07
Totals per starting letter query
-- Get a count of, lets say, people's names that start with each letter
-- from a specific city and state
SELECT LEFT(name, 1) AS letter, COUNT(id) AS total
FROM data_table
WHERE city = ? AND state = ?
GROUP BY letter
ORDER BY letter ASC;
@belsrc
belsrc / distinct_count.sql
Created January 12, 2016 15:09
Get total for each distinct value query
-- Get a count of people in each city from a specific state
SELECT DISTINCT(city) AS city, COUNT(city) AS total
FROM data
WHERE state = ?
GROUP BY city
ORDER BY city ASC;
@belsrc
belsrc / database_size.sql
Last active January 12, 2016 15:14
Database Size
SELECT table_schema AS 'Database name',
SUM(data_length + index_length) / 1024 / 1024 AS 'Size (MB)',
SUM(data_free) / 1024 / 1024 AS 'Free (MB)'
FROM information_schema.TABLES
GROUP BY table_schema