Skip to content

Instantly share code, notes, and snippets.

View kwokhou's full-sized avatar
🎯
Focusing

Andy Yong kwokhou

🎯
Focusing
View GitHub Profile
@kwokhou
kwokhou / WriteStringToFile.cs
Created September 15, 2010 02:29
Write a string into the given flat file (file directory and file name)
//file directory (fileDir) must end with a backslash "\"
private static void WriteFile(string fileDir, string fileName, string fileContent)
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(fileDir + fileName);
sw.Write(fileContent);
sw.Close();
}
@kwokhou
kwokhou / loadTemplate.js
Created June 26, 2013 23:11
Load external template for EmberJS
// Getting a external handlebar template via jQuery.get()
// and compile template and register it to Ember
function loadTemplate(url, name, callback) {
var contents = $.get(url, function(data) {
var compiled = Ember.Handlebars.compile(data);
if (name) {
Ember.TEMPLATES[name] = compiled
}
else {
Ember.View.create({ template: compiled }).append();
@kwokhou
kwokhou / angular-jsonDate.js
Last active March 1, 2016 08:33
AngularJS filter to format ASP.NET JSON Date
// Format a /Date(XXXXXXXXXXXXXXXX)/ into a JSON date object.
angular.module('jsonDate', []).filter('jsonDate', function () {
return function (input, format) {
if (angular.isUndefined(input))
return;
// first 6 character is the date
var date = new Date(parseInt(input.substr(6)));
@kwokhou
kwokhou / angular-autoNumeric.js
Last active April 22, 2024 21:54
AngularJS directive for autoNumeric.js
// Directive for autoNumeric.js
// Require AngularJS, jQuery and autoNumeric.js
angular.module('crunch.ui.numeric', []).directive('crNumeric', [function () {
'use strict';
// Declare a empty options object
var options = {};
return {
// Require ng-model in the element attribute for watching changes.
require: '?ngModel',
// This directive only works when used in element's attribute (e.g: cr-numeric)
@kwokhou
kwokhou / angularjs-routing.js
Created July 10, 2013 10:41
AngularJS Router
angular.module('my.app.routing', [], function ($routeProvider, $locationProvider) {
$routeProvider.when('/path', {
templateUrl: '/path/to/foo.html',
controller: FooControler
});
$locationProvider.html5Mode(true);
});
@kwokhou
kwokhou / isNumber.js
Last active September 21, 2016 07:05
JavaScript Is Number check, alternative to http://api.jquery.com/jQuery.isNumeric/
// Copied from http://stackoverflow.com/a/1830844
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
@kwokhou
kwokhou / SendMail.cs
Last active September 30, 2022 12:37
Sending email with outlook.com via C# SmtpClient
private void button1_Click(object sender, EventArgs e)
{
var mail = new MailMessage();
mail.From = new MailAddress(textBoxFrom.Text);
mail.To.Add(textBoxTo.Text);
mail.Subject = textBoxSubject.Text;
mail.IsBodyHtml = true;
string htmlBody;
htmlBody = textBoxMessage.Text;
mail.Body = htmlBody;
@kwokhou
kwokhou / BitFlags
Created October 7, 2013 23:09
Using bit flags in C#
[Flags]
public enum ExampleEnum
{
A = 1 << 0,
B = 1 << 1,
C = 1 << 2,
D = 1 << 3,
E = 1 << 4,
}
@kwokhou
kwokhou / angular-loading
Last active December 27, 2015 03:39
Angular loading indicator for Ajax request
app.config(function ($httpProvider) {
$httpProvider.interceptors.push(function ($q, $rootScope) {
return {
'request': function (config) {
$rootScope.$broadcast('loading-started');
return config || $q.when(config);
},
'response': function (response) {
$rootScope.$broadcast('loading-complete');
return response || $q.when(response);
@kwokhou
kwokhou / aspnet-boxstarter.txt
Last active August 29, 2015 14:24
Boxstarter config for Windows ASP.NET development
Set-WindowsExplorerOptions -EnableShowFileExtensions -EnableShowFullPathInTitleBar
Enable-MicrosoftUpdate
Install-WindowsUpdate
Set-CornerNavigationOptions -EnableUsePowerShellOnWinX
Update-ExecutionPolicy
choco install git -y
choco install git-credential-winstore -y
choco install conemu -y
choco install diffmerge -y