Skip to content

Instantly share code, notes, and snippets.

View Owen-Mak's full-sized avatar

Owen Mak Owen-Mak

  • Toronto
View GitHub Profile
@Owen-Mak
Owen-Mak / dircheck.sh
Created October 28, 2019 18:19
Added argument check
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Missing arguments."
exit 1
fi
numOfDir=0 #count how many are directories
for entry in "$@" # loop through arugments
@Owen-Mak
Owen-Mak / uri.test.ts
Created April 23, 2018 03:11
Additional tests added
if (!isWindows) {
test('absolute path', function () {
const path = '/foo/bar';
assert.equal(URI.file(path).path, path);
});
test('relative path', function () {
const path = 'foo/bar';
assert.equal(URI.file(path).path, path);
const fileUri1 = URI.parse(`file:foo/bar`);
@Owen-Mak
Owen-Mak / quickOpenScorer.test.ts
Created April 23, 2018 01:21
Update test cases for quickOpenScorer
test('prepareSearchForScoring', function () {
assert.equal(scorer.prepareQuery(' f*a ').value, 'fa');
assert.equal(scorer.prepareQuery('model Tester.ts').value, 'model Tester.ts');
assert.equal(scorer.prepareQuery('Model Tester.ts').lowercase, 'model tester.ts');
assert.equal(scorer.prepareQuery('ModelTester.ts').containsPathSeparator, false);
assert.equal(scorer.prepareQuery('Model' + nativeSep + 'Tester.ts').containsPathSeparator, true);
assert.equal(scorer.prepareQuery('dir' + nativeSep + 'tester.ts').value, 'dir' + nativeSep + 'tester.ts');
assert.equal(scorer.prepareQuery('dir' + nativeSep + 'model tester.ts').value, 'dir' + nativeSep + 'model tester.ts');
});
@Owen-Mak
Owen-Mak / tab.js
Created April 22, 2018 19:14
Work on debugging fixDisplayURL
// hack to deal with about:* pages
const fixDisplayURL = (navigationEntry, controller) => {
if (navigationEntry == null) {
return null
}
navigationEntry = Object.assign({}, navigationEntry)
//console.log("fixDisplayURL-->IN-->", navigationEntry.virtualURL)
navigationEntry.virtualURL = getLocationIfPDF(navigationEntry.virtualURL)
//console.log("fixDisplayURL-->OUT-->", navigationEntry.virtualURL)
@Owen-Mak
Owen-Mak / urlutil.js
Created April 12, 2018 00:04
Only replace whitespace when it is a file scheme
if (case2Reg.test(str) || !case3Reg.test(str) ||
(scheme === undefined && /\s/g.test(str))) {
if (scheme === undefined && /\s/g.test(str)) {
// check to see if undefined scheme is possibly file scheme
let str1 = UrlUtil.prependScheme(str)
if (UrlUtil.isFileScheme(str1)) {
// if it is file scheme, will then replace whitespace with %20
str = str.replace(' ', '%20')
} else {
return true
@Owen-Mak
Owen-Mak / urlutil.js
Created April 11, 2018 23:54
Converting whitespace in the query section of url
if (/\s/g.test(str) && scheme !== undefined) {
// attempt to change query whitespace to %20
var queryIndex = str.search(/\?.*$/)
if (queryIndex > 0) {
var query = str.substring(queryIndex).replace(/\s/g, '%20')
str = str.substring(0, queryIndex) + query
}
}
@Owen-Mak
Owen-Mak / urlutilTest.js
Created April 11, 2018 22:33
Test case for isNotUrl() function
describe('isNotURL', function () {
describe('returns false when input:', function () {
it('is a valid URL', function () {
assert.equal(urlUtil.isNotURL('brave.com'), false)
})
it('is an absolute file path without scheme', function () {
assert.equal(urlUtil.isNotURL('/file/path/to/file'), false)
})
it('is an absolute file path with scheme', function () {
assert.equal(urlUtil.isNotURL('file:///file/path/to/file'), false)
describe('getUrlFromInput', function () {
it('returns empty string when input is null', function () {
assert.equal(urlUtil.getUrlFromInput(null), '')
})
it('returns empty string when input is undefined', function () {
assert.equal(urlUtil.getUrlFromInput(), '')
})
it('calls prependScheme', function () {
assert.equal(urlUtil.getUrlFromInput('/file/path/to/file'), 'file:///file/path/to/file')
})
@Owen-Mak
Owen-Mak / S22.1.3.20_A1_T1.js
Created March 13, 2018 02:59
Test cases for reverse function in Array objects
// Copyright 2018 Owen Mak. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
info: |
The elements of the array are rearranged so as to reverse their order.
The object is returned as the result of the call
esid: sec-array.prototype.reverse
es6id: 22.1.3.20_A1_T2
description: Checking this algorithm, elements are objects and primitives
...