Skip to content

Instantly share code, notes, and snippets.

View jsgao0's full-sized avatar

Anson jsgao0

View GitHub Profile
@jsgao0
jsgao0 / ctest.js
Created June 28, 2016 15:31
CasperJS tests Facebook authorization.
casper.test.begin('Test enroll with Facebook.', 1, function suite(test) {
casper
.start('http://localhost/enroll')
.then(function() { // #1 Test: Register using Facebook but user click cancel button on auth page.
casper.click('#facebookLogin'); // Simulate an user click button 'Login with Facebook'.
casper.waitForPopup(/^https:\/\/www.facebook.com\/login/, function() { // Wait for Facebook login popup.
this.echo('Open Facebook login page when not login yet.'); // The user has not login yet.
});
casper.withPopup(/^https:\/\/www.facebook.com\/login/, function() { // Do something within the popup.
this.evaluate(function() { // Simulate the user enters email and password. Then, click login button of Facebook.
@jsgao0
jsgao0 / testSubmitForm.js
Last active June 16, 2016 09:02
User submits form and redirect instead of clicking then redirect.
casper.test.begin('Test page.', 2, function suite(test) {
casper.start(
'https://cib.icicibank.com/corp/BANKAWAY?Action.CorpUser.Init1.001=Y&AppSignonBankId=ICI&AppType=corporate',
function() {
this.echo(this.getTitle());
test.assertUrlMatch(/BANKAWAY?/, 'Current location is ' + this.getCurrentUrl());
});
casper.then(function(){
this.fill('#rt', {}, true);
@jsgao0
jsgao0 / testRedirectAndBack.js
Last active June 16, 2016 01:42
Test the user behavior when a user click a tag and redirect.
/*
Created by jsgao0 on 2016/06/15.
The intallation guide: http://docs.casperjs.org/en/latest/installation.html
Steps:
1: Install PhantomJS globally. npm install phantomjs -g
2: Install CasperJS globally. npm install casperjs -g
3: Execute tests. casperjs test testRedirectAndBack.js
*/
casper.test.begin('Test redirect and back to URLs.', 5, function suite(test) {
@jsgao0
jsgao0 / dtCompare.cs
Last active June 15, 2016 02:24
C# Datetime Comparison
public class DTC { // DateTimeComparison
public static bool lgr(DateTime a, DateTime b, bool isEqual = false) { // Left Datetime a is greater than right Datetime b. If isEqual is true then return true when the 2 Datetimes both are same.
int result = DateTime.Compare(a, b);
return isEqual ? (result >= 0) : (result > 0);
}
}
@jsgao0
jsgao0 / README.md
Last active June 6, 2016 14:04 — forked from kirankumaramruthaluri/index.html
D3 JS Bar Chart - Simple Win Loss Chart

I transposed the coordinate axis of the chart because the item amount is dynamic.

@jsgao0
jsgao0 / README.md
Last active June 6, 2016 14:15
D3.js Heat Map - Quality Display

I post a tutorial in order that my friend needs a 2D heat map for quailty display.

@jsgao0
jsgao0 / classGroupBy.cs
Last active May 12, 2016 02:59
Group by some property in a class constructor.
public class BusinessHours {
public DateTime openAt { get; private set; }
public DateTime closeAt { get; private set; }
public BusinessHours(DateTime openAt, DateTime closeAt) {
this.openAt = openAt;
this.closeAt = closeAt;
}
}
public class GroceryStore<T> where T : Grocery {