Skip to content

Instantly share code, notes, and snippets.

View fredgdaley2's full-sized avatar

Fred Daley fredgdaley2

View GitHub Profile
@fredgdaley2
fredgdaley2 / ToCsvValue.vb
Last active August 29, 2015 14:08
Get string value prepared for csv file. #fregdaley2 #extension #csv
<Extension()> _
Public Function ToCsvValue(ByVal source As Object, Optional ByVal addDelimiter As Boolean = True) As String
Dim csvValue As String
If source Is Nothing Then
csvValue = ""
Else
csvValue = CStr(source).Trim
End If
If addDelimiter Then
Return If(csvValue.IndexOf(",") > -1, String.Format("""{0}"",", csvValue), String.Format("{0},", csvValue))
@fredgdaley2
fredgdaley2 / designer.html
Last active August 29, 2015 14:12
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-drawer-panel/core-drawer-panel.html">
<polymer-element name="my-element">
<template>
<style>
:host {
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<polymer-element name="my-element">
@fredgdaley2
fredgdaley2 / WaitForFileToBeAccessible.vb
Created June 29, 2016 14:27
Wait for a file to be accessible if not wait 10 seconds and try again.
Public Sub WaitForFileToBeAccessible(ByVal fileWaitingOn As String)
Try
Using fs As FileStream = New FileStream(fileWaitingOn, FileMode.Open, FileAccess.ReadWrite, FileShare.None, 100)
fs.ReadByte()
End Using
Catch ex As Exception
System.Threading.Thread.Sleep(10000)
WaitForFileToBeAccessible(fileWaitingOn)
End Try
End Sub
@fredgdaley2
fredgdaley2 / SmtpAlive.vb
Last active July 21, 2016 16:20
Check if email server is alive
Imports System.Net.Sockets
Public Function SmtpAlive(ByVal hostName As String, ByVal port As Integer)
Using tcp As New TcpClient
Try
tcp.Connect(hostName, port)
Return True
Catch ex As Exception
' server not found
Return False
End Try
@fredgdaley2
fredgdaley2 / AppDataFolder.cs
Created February 22, 2017 01:46
.NET Framework => Core: Getting The App Data Folder
//Credit goes to this blog post https://dotnettips.wordpress.com/2017/02/20/net-framework-core-getting-the-app-data-folder/
//For .Net Core
public static string AppDataFolder()
{
var userPath = Environment.GetEnvironmentVariable(
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
"LOCALAPPDATA" : "Home");
var assy = System.Reflection.Assembly.GetEntryAssembly();
var companyName = assy.GetCustomAttributes<AssemblyCompanyAttribute>()
@fredgdaley2
fredgdaley2 / RetrieveAppSettings.cs
Created February 22, 2017 01:54
Retrieve application settings
//Credit goes to this blog post https://dotnettips.wordpress.com/2013/03/07/retrieving-application-settings/
//USAGE: int serverPort = GetAppSetting<int>("server_port");
public static T GetAppSetting<T>(string key)
{
if (ConfigurationManager.AppSettings.AllKeys.Contains(key))
{
return (T)System.Convert.ChangeType(ConfigurationManager.AppSettings[key],
typeof(T), CultureInfo.InvariantCulture);
}
else
@fredgdaley2
fredgdaley2 / arraystringtonumbers.js
Created June 5, 2017 17:56
JavaScript Array of String to Array of Numbers
Credit goes to this post https://stackoverflow.com/questions/10541770/convert-string-array-to-integer-array Answer from janseeuw.
var arrayOfNumbers = arrayOfStrings.map(Number);
@fredgdaley2
fredgdaley2 / settergetter.js
Created June 7, 2017 20:04
Javascript setter and getter for elements uses jQuery
function setget(selector) {
return {
get: function () {
return $(selector).val();
},
set: function (newValue) {
$(selector).val(newValue);
}
};
}
@fredgdaley2
fredgdaley2 / GetUrlParameters.js
Created June 28, 2017 17:32
Get url parameters from href
//Referenced from https://www.sitepoint.com/get-url-parameters-with-javascript/
function getAllUrlParams(url) {
// get query string from url (optional) or window
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
// we'll store the parameters here
var obj = {};