Skip to content

Instantly share code, notes, and snippets.

View KarateJB's full-sized avatar
💭
May the Force be with you.

JB KarateJB

💭
May the Force be with you.
View GitHub Profile
@KarateJB
KarateJB / removeElement.js
Last active September 12, 2016 09:40
[JS] Remove element from array.
var index = $scope.Agents.indexOf(agent);
$scope.Agents.splice(index, 1);
@KarateJB
KarateJB / WebApi-Get uri parameters.cs
Created August 15, 2016 03:44
[WebApi] Get uri parameters
//Get the url parameters
NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
var qcBsTypeId = nvc["bsType"] ?? String.Empty; //查詢條件 : 作業類別
var qcCustId = nvc["customer"] ?? String.Empty; //查詢條件 : 客戶
var qcScheduleDateFrom = nvc["scheduleDateFrom"] ?? String.Empty; //查詢條件 : 運送日期(From)
var qcScheduleDateTo = nvc["scheduleDateTo"] ?? String.Empty; //查詢條件 : 運送日期(To)
@KarateJB
KarateJB / setTimeout.js
Last active September 12, 2016 09:40
[JS] Set timeout
setTimeout(function () {
// Whatever you want to do after the wait
}, 1000);
@KarateJB
KarateJB / draggable.js
Created September 12, 2016 09:35 — forked from siongui/draggable.js
AngularJS draggable element (position must be absolute)
/**
* @see https://github.com/siongui/palidictionary/blob/master/static/js/draggable.js
* @see http://docs.angularjs.org/guide/compiler
*/
angular.module('draggableModule', []).
directive('draggable', ['$document' , function($document) {
return {
restrict: 'A',
link: function(scope, elm, attrs) {
@KarateJB
KarateJB / moveElment.js
Created September 12, 2016 09:39
[JS] Move element in array
Array.prototype.move = function (old_index, new_index) {
if (new_index >= this.length) {
var k = new_index - this.length;
while ((k--) + 1) {
this.push(undefined);
}
}
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
return this; // for testing purposes
};
@KarateJB
KarateJB / randomNumber.js
Created September 21, 2016 01:09
[JS] Random number in a range
/**
* Returns a random number between min (inclusive) and max (exclusive)
*/
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
/**
* Returns a random integer between min (inclusive) and max (inclusive)
* Using Math.round() will give you a non-uniform distribution!
@KarateJB
KarateJB / package.json
Last active February 13, 2017 03:41
[Angular CLI] Package.json for building old ng2 project
{
"name": "welfare.website",
"version": "1.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"build": "ng build --prod",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
@KarateJB
KarateJB / multiple.js
Created April 2, 2017 02:37
[JS] Multiple without using multiplication or addition.
function multiple(x,y){
return x/(1/y)
}
//Demo
//[1,2,3,4,5].forEach(x=>{console.log(multiple(x,8))})
//>8,16,24,32,40
@KarateJB
KarateJB / countingSort.ts
Created April 2, 2017 02:41
[TypeScript] Counting Sort
private countSort(
rangeMin: number, rangeMax: number, arr: number[]) {
let mappingArr: boolean[] = [];
//Initial
for (let i = rangeMin; i <= rangeMax; i++) {
mappingArr[i] = false;
@KarateJB
KarateJB / jqGrid_dealCells.js
Created May 9, 2017 02:11
[JS] jqGri Deal with cells
var grid = $("#" + jqGridID);
var rows = grid.jqGrid('getGridParam', 'data'); //var rows = grid.getGridParam('data');
var indexes = grid.jqGrid('getGridParam', '_index');
var rowid;
for (rowid in indexes) {
if (indexes.hasOwnProperty(rowid)) {