2019年10月17日 星期四

Javascript combinations enumeration (not fast)

comb=function(a,n){
  var ids=new Array(n).fill(0).map((i,ind)=>ind);
  var res=[];
  //console.log(indexes);
  var evs="";
  for(i in ids)
    evs+=`for(ids[${i}]=((ids[${i}-1]==null)?(-1):ids[${i}-1])+1;ids[${i}]<=a.length-n+${i};ids[${i}]++){\n`;
  evs+=`res.push(a.filter(    (ii,ind)=>(ids.indexOf(ind)!=-1)    ));\n`;
  evs+="}\n".repeat(n);
  console.log(evs);
  eval(evs);
  return (res);
}





2019年9月23日 星期一

Simple dialog / list dialog in javascript using jquery & bootstrap




First, include jquery and bootstrap

2019年9月3日 星期二

WebUSB/Arduino on Windows 8 - How to make it work

Recently I'm playing with arduino and hoped to utilize the WebUSB API to enable cross-platform control over my arduino board. Here's some directions on how to get it work:

Outlines

  • Get a board that is compatible: I used Arduino Leonardo
  • Download ArduinoDroid for Android
  • Download WebUSB library
  • Upload your sketch to the board
  • Install Zadig on your windows to replace the original Driver and let it work

2019年8月27日 星期二

Javascript Permutations Enumeration (not fast)

patt=function(arr){
if(arr.constructor.name!="Array")
  return [];
arr=arr.slice();
if(arr.length==1)
  return [arr];
else if(arr.length==2)
  return [arr,arr.slice().reverse()];
else
 {
  let sum=[];
  let el=arr.shift();
  let darr=patt(arr);
  for(var i in new Array(arr.length+1).fill(0))
    sum.push(...darr.map(item=>
      {
        let cp=item.slice();
        cp.splice(i,0,el);
        return cp;
      }));
  return sum;
 }
};





2019年7月30日 星期二

Webusb test










External library from
https://github.com/webusb/arduino





2019年7月16日 星期二

2019年7月14日 星期日

A javascript analog of python's range

var range=(a,b,c)=>
  {
    if(!b) b=1;
    if(!c) c=1;
    let arr=new Array(Math.floor(Math.abs(a-b)/c)+1).fill(0);
    arr=arr.map((i,ind)=>(ind*(b-a)/(arr.length-1)+a));
    return arr;
  };