Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Busy in getting busier

Ravi Kumar Prasad ravikp7

🎯
Busy in getting busier
View GitHub Profile
View best-route-problem.js
const positions = {
Aman: {
latitude: 0,
longitude: 0,
},
R1: {
latitude: 0,
longitude: 0,
},
R2: {
View codewars.js
function idBestUsers(...months) {
// Get user Ids present in all months
const firstMonth = months[0];
const filteredUsers = firstMonth.filter(userId => {
return months.every(month => month.includes(userId));
});
const userCount = {}; // Stores userId instance counts as key value pair
@ravikp7
ravikp7 / async.js
Created May 14, 2019
Comparing different async JS styles
View async.js
// A library
const getImage = (url, callback) => {};
const imageUrls = [];
// Callback
/**
* This callback style code is least readable.
* It has trust issue as we depend upon getImage library to execute our callback.
* There may be a bug in the library and it may never run the callback
@ravikp7
ravikp7 / index.js
Created Jun 3, 2018
node-usb BeagleBone
View index.js
const usb = require('usb');
const device = usb.findByIds(0x1d6b, 0x0104);
device.open();
for (let i = 0; i < 7; i++) {
let devInt = device.interface(i);
if (devInt.isKernelDriverActive()) devInt.detachKernelDriver();
devInt.claim();
}
device.interfaces.forEach((interfac) => {
console.log(interfac);
@ravikp7
ravikp7 / index.js
Created May 14, 2018
beagleboot adapter
View index.js
'use strict'
const EventEmitter = require('events')
const BeagleBoot = require('beagle-boot')
class BeagleBootAdapter extends EventEmitter {
/**
* @summary USBBootAdapter constructor
* @class
* @example
@ravikp7
ravikp7 / download.js
Created Mar 27, 2018
beaglebone latest images fetch
View download.js
var fs = require('fs')
var http = require('http')
var file = fs.createWriteStream("file.html");
var request = http.get("http://beagleboard.org/latest-images", function(response) {
response.pipe(file);
});
@ravikp7
ravikp7 / output
Created Jun 4, 2017
Schemapack encoding doesn't work for array of more than 9 objects.
View output
ravi@ravi-Lenovo-G50-45:~/beagle-js$ node serializer-test.js
undefined:3
var ref1=json;var ref2=ref1['a'];var ref3=ref2[0];var ref4=ref2[1];var ref5=ref2[10];var ref6=ref2[2];var ref7=ref2[3];var ref8=re
f2[4];var ref9=ref2[5];var ref10=ref2[6];var ref11=ref2[7];var ref12=ref2[8];var byteC=0;byteC+=1;byteC+=1;byteC+=bag.dynamicByteC
ounts['string'](ref5['pad']);byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=1;byteC+=bag.getVarUIntByteLength(ref2.l
ength);for (var j2=10;j2<ref2.length;j2++) { var ref13xn=ref2[j2];byteC+=1;}var wBuffer=bag.allocUnsafe(byteC);bag.byteOffset=0;if
(typeof(ref3['a']) !== 'number'||ref3['a']<0||ref3['a']>255){bag.throwTypeError(ref3['a'],'number',0,255,'uint8');}bag.byteOffset
= wBuffer.writeUInt8(ref3['a'], bag.byteOffset, true);if (typeof(ref4['b']) !== 'number'||ref4['b']<0||ref4['b']>255){bag.throwTy
peError(ref4['b'],'number',0,255,'uint8');}bag.byteOffset = wBuffer.writeUInt8(ref4['b'], bag.byteOffset, true);if (typeof(ref5['p
ad']) !== 'string'){bag.throwTypeE
@ravikp7
ravikp7 / output
Created Jun 2, 2017
parsing test
View output
ravi@ravi-Lenovo-G50-45:~/beagle-js$ node serializer
<Buffer 06 ff ff ff ff ff ff 08 00 06 a0 f6 fd 8a e9 1a>
{ h_dest: [ 6, 255, 255, 255, 255, 255 ],
h_source: [ 255, 8, 0, 6, 160, 246 ],
h_proto: -630 }
@ravikp7
ravikp7 / main.c
Last active May 27, 2017
checking bootp packet
View main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libusb.h>
#include <linux/ip.h>
#include <unistd.h>
#include <sys/stat.h>
#include "rndis.h"
#include "ether2.h"
@ravikp7
ravikp7 / main.js
Created May 27, 2017
Testing parsing
View main.js
var usb = require('usb');
var Parser = require('binary-parser').Parser;
// Connect to BeagleBone
var device = usb.findByIds(0x0451, 0x6141);
//console.log(device);
device.open();
var interface = device.interface(1);