![]() | submitted by ksalim87 to u/ksalim87 [link] [comments] |
submitted by goodlove20 to binaryoption [link] [comments]
![]() | submitted by emadbably to OptionsInvestopedia [link] [comments] |
![]() | submitted by asrclub to u/asrclub [link] [comments] |
# This is a comment print('Print with formatting') printf('Print without formatting') # Variable Declaration variable string = 'Hello World' print(string) # If Statement variable boolean = true if boolean == true { print('True') } else { print('False') } # For Loop table numbers = [1, 2, 3, 4, 5] for number in numbers { print(number) }and this is the nodejs compiler script
const fs = require('fs') const file = process.argv[2] fs.readFile(file, (err, data) => { if (err) throw err const lines = data.toString().split('\n') const compiled = [] for (let line of lines) { line = line.trim() if (line.length > 0) { // Check if line is a comment line = line.replace('#', '//') // Functions line = line.replace('print(', 'console.log(') line = line.replace('printf(', 'process.stdout.write(') // Variable Declaration if (line.startsWith('variable ') && line.includes(' = ')) { const variableName = line.split(' = ')[0].replace('variable ', '') const variableValue = line.split(' = ')[1] if (variableName && variableValue) { line = `let ${variableName} = ${variableValue}` } } // Variable Assignment const variableNameAssign = line.split(' = ')[0] const variableValueAssign = line.split(' = ')[1] if (variableNameAssign && variableValueAssign) { line = `${variableNameAssign} = ${variableValueAssign}` } // Table Declaration if (line.startsWith('table ') && line.includes(' = ')) { const tableName = line.split(' = ')[0].replace('table ', '') const tableValue = line.split(' = ')[1] if (tableName && tableValue) { line = `let ${tableName} = ${tableValue}` } } // If statement if (line.includes('if ')) { line = line.replace('if ', 'if (') line = line.replace(' {', ') {') line = line.replace('==', '===') } // For loop if (line.includes('for ')) { line = line.replace('for ', 'for (let ') line = line.replace(' in ', ' of ') line = line.replace(' {', ') {') } compiled.push(line) } } fs.writeFile('compiled.js', compiled.join('\n'), (err) => { if (err) throw err }) })its really good plz upvote downscript
var msgLen = input.readUInt32LE(0) var dataLen = msgLen + 4 if (input.length >= dataLen) { var content = input.slice(4, dataLen) var json = JSON.parse(content.toString()) handleMessage(json) }})
var header = Buffer.alloc(4) header.writeUInt32LE(buffer.length, 0) var data = Buffer.concat([header, buffer]) process.stdout.write(data)}
![]() | I'm gonna cut to the chase right away: this is not a review of the keyboard itself but rather a rundown of what I did to it to make it work for me. Some of you may find this useful as I did a lot of detective work both on the hardware and the software sides, especially on how to get the HID to work. submitted by najnajjak to MechanicalKeyboards [link] [comments] My goal was to program the keyboard in such a way that the layer switching would happen automatically based on which is your currently active window. So, for example, if you have Firefox open then the layer on your keyboard would be automatically set to the Firefox layer. Then, in the moment you switch to something else, let's say Discord, the layer would be immediately switched to the Discord layer, and so on. I will try to explain it in simple words how I did this, albeit it might get a bit technical. I'll not be spamming with the obvious stuff or something that you can easily find on the net. The GMMK ProIt's real nice. I got it because it's 75% hot-swappable with QMK support. It's mostly the vanilla version, I've done nothing to the stabs or internally, it is as it comes in the box.https://preview.redd.it/qx3ts8f6rja91.png?width=4000&format=png&auto=webp&s=c0bc1777511370cb6d78748ac8ba230940d5d211 The switches are as follows:
I put no lube, good switches are good even when unlubed. https://preview.redd.it/rt6u0ebbsja91.png?width=4000&format=png&auto=webp&s=50d44028755b57135a0856ddd2f6a1c87de34ed6 The keycaps are Glorious Celestial Fire (for most of the keys), I didn't care much how they look, so I let my gf pick them. The function row and the right-most macro row are probably some Chinese clear black ABS crap, but they are really doing the job great for my setup. Functions and LayeringI got into custom mechanical keyboards only because I wanted to bind keys to some funky things. I move my keyboard a lot between computers in my daily work, so simply installing Autohotkey or whatever wasn't a sustainable option as it would require setting it up manually on every machine.To select a layer you have to hit and hold the FN button, which I've conveniently put on the left of the arrow keys. Holding that key puts you into a special "layer selection mode". https://preview.redd.it/iz387rwrsja91.png?width=4000&format=png&auto=webp&s=56fc961ffabd82c7605e65ab22462e05ab3204f9 There are two types of selection you can make: - Layer: You can switch between 12 available layers, each corresponding to one of the function keys. The selected one has it's LED lit up green and all other are red. Each layer is targeted at a specific program. I currently have bindings for Firefox (or browsers in general), Visual Studio, Discord and Windows File Explorer. I'll probably add more in the future. - Feature: You can switch 4 features on or off on the right-most keys, with a green LED being on and a red LED being off. I've currently set the bottom one to switch the arrow keys as mouse on or off, and the one above it to switch auto-shift on or off. The topmost two will be empty until I find something useful to bind them to. The LEDsI don't really like the pulses and waves and whatever, and since the GMMK Pro has per-key lighting and QMK supports editing it per-key, I decided to use the LED lighting for something that's actually useful: indicating what the key does in a specific layer. It's really confusing if F4 does different things in different layers, so a bit of color goes a long way to help. https://preview.redd.it/bag5tluhwja91.png?width=4000&format=png&auto=webp&s=890e5e04e5aac568c80596d1751b655dd0a2a898 For the most part, keys that are lit up in red are binded to something like closing tabs, adding breakpoints, mute/unmute mic, and stuff that's actually has some side effect on the state of the program. Keys that are green indicate something that's created or run, so for example: creating new tabs or files, refreshing, running, etc. Blue ones are either switching (tabs, windows) or searching for something. Yellow ones have intermediate side-effects, something like copying, or making a build, etc. Other colors I use are mostly unique because those features don't quite fit into the categories listed above. Side-lights are colored in the same scheme as the program that the layer targets. QMK Setup
Firefox
https://preview.redd.it/tn5l5clvxja91.png?width=4000&format=png&auto=webp&s=21dbef7308491a85de2ef66c6344edc86f3a394a Visual Studio
https://preview.redd.it/656pmmuhyja91.png?width=4000&format=png&auto=webp&s=fa230ac874af1664c087e6faf19a967e5b211c0d Discord
https://preview.redd.it/rvvr3nv6zja91.png?width=4000&format=png&auto=webp&s=cfb5700864d5d818ee312544f46d48157782bada File Explorer
https://preview.redd.it/i0byx8ytzja91.png?width=4000&format=png&auto=webp&s=c9ef2b401530de70d5651105ff731b0f601f4a5b The arrow keys as mouse feature is layered on top of any of these layers, so changing layers doesn't affect whether you can use the arrow keys to control the cursor. Even the LEDs are layered on top, so if the arrows move the cursor they are red. I use the QMK function layer_move() to switch between layers and layer_on() to layer the arrow-keys-as-mouse on top of the standard layer. The layer which is used to switch layers is also a standard QMK layer. I use the following function for switching between layers: bool process_layer_control(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case SK_LYR_U: if (record->event.pressed) { last_active_layer++; if (last_active_layer > get_layer_count()) { last_active_layer = 0; } } break; case SK_LYR_D: if (record->event.pressed) { last_active_layer--; if (last_active_layer < 0) { last_active_layer = get_layer_count(); } } break; case SK_LAYER: if (record->event.pressed) { last_active_layer = active_layer; active_layer = MP_FUNCTIONAL; layer_move(MP_FUNCTIONAL); } else { active_layer = last_active_layer; jump_to_active_layer(); } break; } for (uint32_t i = BEGIN_LAYERS; i < CUSTOM_KEYCODES_COUNT; i++) { if (record->event.pressed) { if (keycode == i) { last_active_layer = i - BEGIN_LAYERS - 1; } } } return false; }The jump_to_active_layer(void) function simply does a stateless transition to the new layer state. void jump_to_active_layer(void) { active_layer = active_layer > get_layer_count() ? 0 : active_layer; active_layer = active_layer < 0 ? get_layer_count() : active_layer; layer_move(active_layer); if (custom_feature_flags & CFF_ARROWS_AS_CURSOR) { layer_on(MP_ARROWS_MOUSE); } uprintf("active_layer: %d\n", active_layer); }All the actual processing of the keypresses is done inside the QMK process_record_user(uint16_t keycode, keyrecord_t *record) function. There are some GMMK Pro-specific things I've done, one of them is mapping the LED sidelights. I'm doing that through these functions: void set_sidelights_color(int r, int g, int b) { for (int i = 0; i < 8; i++) { rgb_matrix_set_color(LED_SIDE_LEFT[i], r, g, b); rgb_matrix_set_color(LED_SIDE_RIGHT[i], r, g, b); } } void set_sidelights_colors(int r1, int g1, int b1, int r2, int g2, int b2) { for (int i = 0; i < 4; i++) { rgb_matrix_set_color(LED_SIDE_LEFT[i], r1, g1, b1); rgb_matrix_set_color(LED_SIDE_RIGHT[i], r1, g1, b1); } for (int i = 4; i < 8; i++) { rgb_matrix_set_color(LED_SIDE_LEFT[i], r2, g2, b2); rgb_matrix_set_color(LED_SIDE_RIGHT[i], r2, g2, b2); } }All other LED work is basically done manually by a bazillion calls to the QMK rgb_matrix_set_color() function, inside the QMK rgb_matrix_indicators_kb() function. The arrow-keys-as-mouse featureit's neat. When this feature is activated you can use the arrow keys to move the mouse cursor. Additionally, the right shift is left click, M4 is right-click and M3 is middle click. When this feature is activated the wheel functions as a scroll wheel, otherwise it's simply a volume wheel. Allows me to only use the keyboard without ever touching the mouse.Custom HID protocolI spent the most time to figure out how to switch layers based on the currently active window. To do this I created a custom HID protocol which is dead simple to implement, but totally cursed when it comes to finding out where to even start. So, I hope the following part might help clear some things up.I'm sending (a maximum of) 32 bytes of data over HID which contain some information, either from the OS to the keyboard or vice versa. I leave the first and the second byte as they are, as they may contain some special data. The third byte indicates which layer should be set on the keyboard. Since it is a byte and adheres to the 0-255 limit, it can switch between 256 different layers which is more than enough (I've predefined 12 layers). So if the HID message is something like 00 00 0A ... it would switch the profile to the 10-th one. It's dead simple and it doesn't really need to be more complex. You can catch the HID message in QMK using the raw_hid_receive() function. In my case, it looks like this: void raw_hid_receive(uint8_t *data, uint8_t length) { if (length > 1) { active_layer = data[1]; jump_to_active_layer(); } raw_hid_send(data, length); }Note that I also call raw_hid_send() here, so that I can easily see what's going on in some OS-side console. That solves the problem of switching layers from the OS, but what about searching on Google for the selected text? The selected text first needs to be saved somewhere where it can be easily accessed by an external program. The clipboard is a perfect candidate for this because there are libraries for almost any language which allow modifying the clipboard. Granted, the firmware on the keyboard can send a CTRL+C key combination to copy to clipboard, but it is impossible for the firmware on the keyboard to read the actual value of what has been copied, concatenate it to a string and then send it via HID, and even if it weren't impossible it would be really impractical. So, it's best that the keyboard actually sends a specific command via HID to the program on the OS side and let it do all the dirty work. For this I'm using the fourth byte, simply to avoid any funky conflicts and ambiguities. Again, since the limit is 256, that's 256 commands I can send in this way, which is more than enough for my purposes. I send the message with the command in the following manner: void send_hid_byte(uint8_t byte_value) { uint8_t data[32]; data[2] = byte_value; raw_hid_send(data, 32); }Each value I send means something different, and these values can be customized to mean whatever: 1 (00 00 00 01 ...) = open Facebook 2 (00 00 00 02 ...) = open Twitter 3 (00 00 00 03 ...) = open YouTube and search for the selected text 4 (00 00 00 04 ...) = open Instagram 5 (00 00 00 05 ...) = open Google and search for the selected textNow, even with the HID protocol set, there needs to be a program on the OS side which can send and read HID messages using the special protocol. I tried different approaches of implementing this program in different languages and I landed on NodeJS using the node-hid library. Just for the record, I absolutely despise doing things like these in JavaScript (YUCK!), but the libraries I tried in C couldn't properly initialize the HID stuff on the GMMK Pro, so I had to stick with what worked (yuck and double yuck!). All libraries I'm using are available through npm. To initialize the device I did something like: var devices = HID.devices(); var deviceInfo = devices.find(function (d) { var isGmmkPro = d.vendorId === 0x320F && d.productId === 0x5044; return isGmmkPro && d.usagePage === 0xFF60 && d.usage === 0x61; }); if (deviceInfo) { var device = new HID.HID(deviceInfo.path); }The vendorID and productID are specific to the device/keyboard you are using, you can find this information either in the Device Manager on Windows, or you can find it in the config file for your specific keyboard make/model (for GMMK Pro it is under [QMK]\qmk_firmware\keyboards\gmmk\pro\config.h) To get the currently active window I'm using the library called electron-active-window. It was mostly 'the method of multiple futile attmepts' that got me to use it (or anything really in NodeJS). This is a really shitty way of doing it but it works well: setInterval(() => { activeWindows().getActiveWindow().then((result) => { activeProgram = result.windowClass; activeProfile = 0x00; if (activeProgram.toLowerCase().includes("firefox")) { activeProfile = 0x01; } else if (activeProgram.toLowerCase().includes("devenv")) { activeProfile = 0x02; } else if (activeProgram.toLowerCase().includes("discord")) { activeProfile = 0x03; } else if (activeProgram.toLowerCase().includes("explorer")) { activeProfile = 0x04; } if (activeProfile != previousProfile) { previousProfile = activeProfile; device.write([0x00, 0x00, activeProfile]); } }); }, 60)The device.write() function will send the HID message to the firmware on the keyboard, whatever it may be. Now, to receive a message from the keyboard firmware I do: device.on("data", OnReceiveDataFromHID);And the callback function looks like this: async function OnReceiveDataFromHID(data) { if (data[2] == 1) { ExecPowershellCommand('Start https://www.facebook.com/'); } if (data[2] == 2) { ExecPowershellCommand('Start https://www.twitter.com/'); } if (data[2] == 3) { var clipboardText = await ExecPowershellCommand('Get-Clipboard'); ExecPowershellCommand('Start "https://www.youtube.com/results?search_query=' + clipboardText + '"'); } if (data[2] == 4) { ExecPowershellCommand('Start https://www.instagram.com/'); } if (data[2] == 5) { var clipboardText = await ExecPowershellCommand('Get-Clipboard'); ExecPowershellCommand('Start "https://www.google.com/search?q=' + clipboardText + '"'); } }With the powershell-executing function looking something like: function ExecPowershellCommand(command) { const { exec } = require('child_process'); return new Promise(function (resolve) { exec(command, { 'shell': 'powershell.exe' }, (error, stdout, stderr) => { resolve(stdout); }); }); }And that's it! I've built a single exe from the NodeJS stuff that I carry around with me, but it works even without it for the most part. I plan on adding more layers for the programs I use, but any suggestions you might have are fullhartedly welcome, there are a lot of blanks still. The full source code can be found on GitHub: https://github.com/martinpetkovski/GmmkProFirmware (it's a total mess, let's not focus on the shittyness of it for now :D) |
![]() | Hi! Been using i3 for a while now so I felt the time was right to write my own status script. The first thing I did was volume and made one that used ANSI color codes to display a bar that faded from green to red, depending on how high my volume was. However I can't add this to i3bar even though it would look really cool. submitted by Komali09 to i3wm [link] [comments] Is there something similar to ANSI codes in i3bar? I know other bar-type applications have their own methods of changing colors but I can't find one for i3bar. Here is my script (ran with nodejs) #!/usbin/node let print = s => process.stdout.write(s); var percentColors=[{pct:0,color:{r:0,g:255,b:0}},{pct:.5,color:{r:255,g:255,b:0}},{pct:1,color:{r:255,g:0,b:0}}],rgP=function(o){for(var r=1;rhttps://preview.redd.it/8deprkg4fl991.png?width=1086&format=png&auto=webp&s=bf7aa6b36714ac29a3aff3fbd3c230f879d16db3 |
const { exec } = require('child_process') // // EDIT THIS const FILE_PATH = "movie.mp4" // // const CMD = `webtorrent-hybrid seed ${FILE_PATH} --keep-seeding --port 80 -q` exec(CMD, (error, stdout, stderr) => { if (error) { console.error("error", error.message) return; } if (stderr) { console.error(stderr) } if (stdout) { console.log(stdout) } })Exit and save the file` in the nano editor. Now lets turn this into a service!
Now save and run this file on a webserver. You could just run python -m http.server --port 80 and then open your web browser to http://localhost to preview.Movie player loading....
![]() | I am creating a web application where i want to open ssh terminal (https://github.com/huashengdun/webssh) with an event listener on frontend and spawn() method in backend nodejs. I built an api to trigger that command from front-end but the problem is that the it's returning stderr which is fine but how can i handle that in my frontend as i want to show the terminal in submitted by False_Mountain_7289 to learnjavascript [link] [comments] |
fs.writeFileSync(path + fileName+".sh" , cmdToWrite,(err)=> { execSync((cmdToLaunch),(stdout, stderr)=> { /* irrelevant */ }); });but i get a:
/bin/sh: 1: at: not found (node:23575) UnhandledPromiseRejectionWarning: Error: Command failed: at now -f path/fileName.sh /bin/sh: 1: at: not found and UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
curl --location --request POST '192.168.0.249:3000/fmi/data/v1/databases/MyDatabaseName/sessions' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic YmFuYW5hZm9yc2NhbGU6aHVudGVyMg==' \ --data-raw '{}'Of course, you'll need to replace the IP address with your server's IP address;MyDatabaseName with the name of your database; and the Authorization header should have your own auth info, Base64-encoded.
Base.redirect_stdout الدالة redirect_stdout([stream]) -> (rd, wr) قم بإنشاء توجيه سيتم إعادة توجيه كل إخراج STDOUT C و Julia إليه. إرجاع tuple (rd, wr) تمثل نهايات الأنبوب. يمكن الآن قراءة البيانات المكتوبة إلى STDOUT من هناك العديد من الخيارات عند استعادة قاعدة البيانات، ولكن عملية الاستعادة لا يمكنها العمل دون وجود قاعدة بيانات بالفعل ضمن العنقود الخاص بك، لذا عليك إنشاءها ثم الاستعادة إليها كما يلي: bash-4.2$ createdb hsoubguide bash-4.2$ pg_restore ... هناك العديد من الخيارات عند استعادة قاعدة البيانات، ولكن عملية الاستعادة لا يمكنها العمل دون وجود قاعدة بيانات بالفعل ضمن العنقود الخاص بك، لذا عليك إنشاءها ثم الاستعادة إليها كما يلي: bash-4.2$ createdb hsoubguide bash-4.2$ pg_restore --forma أحداث Process. الكائن process هو نسخة من EventEmitter.. الحدث 'beforeExit'. أُضيف في الإصدار: 0.11.12. يُطلَق الحدث 'beforeExit' عندما تفرغ Node.js من حلقة الأحداث (event loop) ولا يوجد عمل إضافي لجدولته. بشكل طبيعي، عملية Node.js سوف تنتهي عندما لا يكون هناك ...
[index] [11903] [8936] [14407] [9322] [3227] [678] [10657] [5023] [2393] [10954]
This video is unavailable. Watch Queue Queue. Watch Queue Queue وصل المفاجئه اقوى روبوت 98% وداعا للخساره فى الخيارات الثنائيه!! واهلا بتحقيق مئات الدولارات يوميا!! وصل المفاجئه اقوى روبوت 98% وداعا للخساره فى الخيارات الثنائيه!! واهلا بتحقيق مئات الدولارات يوميا!! This video is unavailable. Watch Queue Queue. Watch Queue Queue This video is unavailable. Watch Queue Queue. Watch Queue Queue
test2