الكائن Process - موسوعة حسوب

أفضل وسطاء الخيارات الثنائية - العقل السليم | حقائق ومعلومات عامة

أفضل وسطاء الخيارات الثنائية - العقل السليم | حقائق ومعلومات عامة submitted by ksalim87 to u/ksalim87 [link] [comments]

الكورس الشامل لتعليم الخيارات الثنائية(قناص الاوبشن)

submitted by goodlove20 to binaryoption [link] [comments]

شرح التداول بالروبوت في بورصة الخيارات الثنائية iQBot

شرح التداول بالروبوت في بورصة الخيارات الثنائية iQBot submitted by emadbably to OptionsInvestopedia [link] [comments]

اقوى كتاب في مجال الخيارات الثنائية

اقوى كتاب في مجال الخيارات الثنائية submitted by asrclub to u/asrclub [link] [comments]

NodeJS inserting unwanted characters into my string, stdout showing garbage!

Hi all,
This little problem has been driving me mad all day but hopefully one of you will know the answer to it.
I'm attempting to output single byte CP437 characters (ANSI) to the console and even though I'm doing this following:
process.stdout.write('\xB0\xB1\xB2\n');
The output to the console will be a string of characters with these hex codes:
c2 b0 c2 b1 c2 b2
Any ideas why Node is prepending my bytes with 0xC2?
As a test I wrote simple program in C which takes a string argument and outputs that argument to stdout. If I use NodeJS to call that program passing in the string I'll get the same result.
The next test was to have the C program output 0xB0 0xB1 0xB2 directly to the console if no arguments are passed in. This worked fine and I saw 3 ANSI shade characters in the console. This also worked fine if I called it in NodeJS using execSync like so:execSync('./ansiOut', {stdio: 'inherit'});
Another test was to have NodeJS call the C program using exec and write its output to the console using process.stdout.write(). I ended up with a strange result where C reports the string is B0,B1,B2,0A which is correct but the output in the console is completely messed up. I'm really not sure what's going on in this instance but not so bothered about solving it.
I'll list out my .js and .c files here, they aren't too long.
Any help with this would be most appreciated, I'm totally stuck with this. I was thinking I could use the C program to clean up the NodeJS output but I don't think the extra characters are consistently 0xC2 for all symbols. I'm really hoping it's some 'don't output UTF-8' setting or something similar.
Thanks
Hypnoshock.
callAnsiOut.js
const { exec, execSync } = require("child_process");
// Outputs the characters as expected console.log("1) Calling ./ansiOut with no args. Default output generated by C"); execSync('./ansiOut', {stdio: 'inherit'});
// Outputs the characters prepended with C2 console.log("2) Calling ./ansiOut with CP437 bytes as argument"); execSync('./ansiOut \xB0\xB1\xB2', {stdio: 'inherit'});
// Has the same affect of producing C2 B0 C2 B1 C2 B1 console.log("3) Calling nodeJS process.stdout.write() using a string of CP437 bytes"); process.stdout.write('\xB0\xB1\xB2\n');
// also C2 B0 C2 B1 C2 B1 console.log("4) Calling ./ansiOut using exec() passing it's output into process.stdout.write"); exec('./ansiOut', (error, stdout, stderr) => { process.stdout.write(stdout); });
ansiOut.c
#include #include
int main(int n, unsigned char *args[]) {
if (n > 1) { printf(args[1]);
printf("\n"); for (int i = 0; i < strlen(args[1]); i ++) { printf(" %02x", (unsigned char)args[1][i]); } printf("\n"); } else { unsigned char str[] = {0xB0, 0xB1, 0xB2, 0x0A}; printf(str); for (int i = 0; i < sizeof str; i ++) { printf(" %02x", (unsigned char)str[i]); } printf("\n"); return 0; } } Edit: I accidentally submitted the post before I had finished!
Output to SyncTerm (which supports CP437). Even if doing this test in a standard termal like iTerm the C program will still report those extra characters although the console output will be questions marks in place of the shade characters (expected)
submitted by hypnoshock to node [link] [comments]

i made my own programming language

the language is called down(syndrome)script
# 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
submitted by FormerAccident to programminghorror [link] [comments]

process.stdin.read() without using process.stdin.on('readable', ()=.{})

I use the same algorithm as a Native Messaging host for QuickJS and Deno.
The algorithm is as follows
```

!deno run

// Deno Native Messaging host // guest271314, 10-5-2022 async function getMessage() { const header = new Uint32Array(1); await Deno.stdin.read(header); const output = new Uint8Array(header[0]); await Deno.stdin.read(output); return output; }
async function sendMessage(message) { const header = Uint32Array.from( { length: 4, }, (_, index) => (message.length >> (index * 8)) & 0xff ); const output = new Uint8Array(header.length + message.length); output.set(header, 0); output.set(message, 4); await Deno.stdout.write(output.buffer); }
async function main() { while (true) { const message = await getMessage(); await sendMessage(message); } }
try { main(); } catch (e) { Deno.exit(); } ```
This is the current Node.js Native Messaging host I am using https://github.com/simov/native-messaging/blob/masteprotocol.js
``` module.exports = (handleMessage) => {
process.stdin.on('readable', () => { var input = [] var chunk while (chunk = process.stdin.read()) { input.push(chunk) } input = Buffer.concat(input)
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) } 
})
function sendMessage (msg) { var buffer = Buffer.from(JSON.stringify(msg))
var header = Buffer.alloc(4) header.writeUInt32LE(buffer.length, 0) var data = Buffer.concat([header, buffer]) process.stdout.write(data) 
}
process.on('uncaughtException', (err) => { sendMessage({error: err.toString()}) })
return sendMessage
} ```
and https://github.com/simov/native-messaging/blob/mastenodejs/example.js
```

!/home/s/.nvm/versions/node/v8.11.2/bin/node

// Might be good to use an explicit path to node on the shebang line // in case it isn't in PATH when launched by Chrome
var sendMessage = require('../protocol')(handleMessage)
function handleMessage (req) { if (req.message === 'ping') { sendMessage({message: 'pong', body: 'hello from nodejs app'}) } } ```
I would prefer to not use process.stdin.on('readable', () => {}), rather, use the same JavaScript algorithm for all JavaScript runtimes.
I tested yesterday and the OS froze due to node using 100% CPU for a while loop.
Is this possible using Node.js?
submitted by guest271314 to node [link] [comments]

Hi Having a little trouble with spawn and pipes. Can you give me a hand?

I'm writing a little wrapper to the lzma command in Linux but the program refuses to write to stdout because it believes to be in an interactive terminal: lzma: Compressed data cannot be written to a terminal.
Here's the SO question with code:
https://stackoverflow.com/questions/73580339/how-to-make-spawned-process-know-its-not-writing-to-a-terminal-nodejs
submitted by definitive_solutions to node [link] [comments]

GMMK Pro Build + QMK and HID tips & tricks

GMMK Pro Build + QMK and HID tips & tricks
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.
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 Pro

It'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:
Make Type Location
Glorious Lynx Linear alphas, arrows
Cherry MX Black (Heavier) Linear space bar
Kailh Box Royal Tactile F keys, tilde, pipe
JWK Musetsu (More) Tactile most mod keys
Kailh Box Navy Clicky enter, esc, backspace, print screen, M keys, right shift
The rationale behind this is that I want my alphas to be really soft and smooth because they can't do any real harm if mispressed, but my functional keys to have the additional "confirmation" bump on them, so that I don't do something stupid by accident (or if I do, I should know immediately).
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 Layering

I 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 LEDs

I 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

Key Description
PS Print Screen
M1-M4 Right-most macro keys, top to bottom
A1 The key right of the space bar
A2 The key to right of A1

Firefox
Key What it does
F1 Previous Tab
F2 Next Tab
F3 New Tab
F4 Close Tab
F5 Refresh
F6 Focus address bar
F7 Open last closed tab
F8 Open downloads window
F9 Open Facebook
F10 Open Twitter
F11 Open YouTube and search for the text you have in the clipboard
F12 Open Instagram
PS Open Google and search for the clipboard text
M1 Delete
M2 Copy current link
M3
M4
A1 Back
A2 Forward

https://preview.redd.it/tn5l5clvxja91.png?width=4000&format=png&auto=webp&s=21dbef7308491a85de2ef66c6344edc86f3a394a
Visual Studio
Key What it does
F1 Save all
F2 Open corresponding h/cpp file
F3 Find all, use the clipboard
F4 Open file
F5 Run
F6 Build
F7 Break
F8 Stop and Re-build
F9 Breakpoint
F10 Step over
F11 Step into
F12 Go to definition/declaration
PS Open Google and search for the clipboard text
M1 Delete
M2 Comment out selection
M3 Uncomment selection
M4 Format everything
A1 Back
A2 Forward

https://preview.redd.it/656pmmuhyja91.png?width=4000&format=png&auto=webp&s=fa230ac874af1664c087e6faf19a967e5b211c0d
Discord
Key What it does
F1 Previous server
F2 Next server
F3 Previous channel
F4 Next channel
F5 Previous unread message
F6 Next unread message
F7 Emoji window
F8 GIF window
F9 Upload file
F10 Pinned messages
F11 Find
F12 Go to current voice channel
PS Mute/Unmute mic
M1 Delete
M2 Mark all as read
M3
M4
A1 Back
A2 Forward

https://preview.redd.it/rvvr3nv6zja91.png?width=4000&format=png&auto=webp&s=cfb5700864d5d818ee312544f46d48157782bada
File Explorer
Key What it does
F1 File properties
F2 Rename
F3 Search
F4 Close window
F5 Up
F6 Focus address bar
F7
F8
F9 Duplicate current window
F10 Copy
F11 Paste
F12 New folder
PS New file
M1 Delete
M2
M3
M4
A1 Back
A2 Forward

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 feature

it'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 protocol

I 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 text 
Now, 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)
submitted by najnajjak to MechanicalKeyboards [link] [comments]

Why does RSS constantly grow when reading data from a child process and calling process.stdout.write()?

The Node.js Native Messaging host creates a child process and streams captured system audio to the browser https://github.com/guest271314/captureSystemAudio/blob/mastenative_messaging/capture_system_audio/capture_system_audio_node.js.
I noticed that RSS grows constantly while the program is running (e.g., beginning at 49MB, increasing to 58MB in 6 minutes). Why?
```

!node

// Node.js Native Messaging host // https://github.com/simov/native-messaging/blob/masteprotocol.js // https://github.com/simov/native-messaging/blob/mastenodejs/example.js // Might be good to use an explicit path to node on the shebang line // in case it isn't in PATH when launched by Chrome process.stdin.on('readable', () => { let input = []; let chunk; while ((chunk = process.stdin.read())) { input.push(chunk); } input = Buffer.concat(input); const msgLen = input.readUInt32LE(0); const dataLen = msgLen + 4; if (input.length >= dataLen) { const content = input.slice(4, dataLen); const json = JSON.parse(content.toString()); handleMessage(json); } });
function sendMessage(msg) { const buffer = Buffer.from(JSON.stringify(msg)); const header = Buffer.alloc(4); header.writeUInt32LE(buffer.length, 0); const data = Buffer.concat([header, buffer]); process.stdout.write(data); }
process.on('uncaughtException', (err) => { sendMessage({ error: err.toString() }); });
function handleMessage(input) { const [command, ...args] = input.split(' '); let { spawn } = require('child_process'); let child = spawn(command, args); child.stdout.on('data', (data) => { sendMessage([...new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT)]); }); child.stderr.on('data', (data) => { // sendMessage(data); }); child.on('close', (code) => { // sendMessage('closed'); }); } ```
submitted by guest271314 to node [link] [comments]

i3bar - Multiple colors in one full_text

i3bar - Multiple colors in one full_text
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.

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;r require("child_process").execSync(s, {stdio: 'pipe'}).toString().replace(/\n$/g,''); let volume = _ => parseInt(cmd(`amixer sget Master`) .split(" [")[1] .split("%]")[0]); print('{ "version": 1 }') print('[') print("[]") setInterval(_=>{ let vol = volume(); if(vol > MAX_VOLUME) { cmd(`pactl set-sink-volume @[email protected] ${MAX_VOLUME}%`); vol = MAX_VOLUME; } //█ print(`,[{"full_text": "Volume (${(100*(vol/MAX_VOLUME)).toFixed(1)}%) [${ ( "\0".repeat((vol/MAX_VOLUME)*NUM_VOL_BARS) + '-'.repeat(NUM_VOL_BARS) ).substring(0,NUM_VOL_BARS).replace(/\0/g, (_,i)=>{ // return `\x1b[38;2;${rgP(i/NUM_VOL_BARS)}m█\x1b[0m` // --- THIS WORKS IN TERMINAL return `█` }) }]", "color": "#00ff00"}\n`) }, 10) 
https://preview.redd.it/8deprkg4fl991.png?width=1086&format=png&auto=webp&s=bf7aa6b36714ac29a3aff3fbd3c230f879d16db3
submitted by Komali09 to i3wm [link] [comments]

How To: create a persistent seeder server using Webtorrent

Who is this for

Want to know how to serve a video reliably over the internet using webtorrent? This is how you do it.
Get a personal cloud computer. The best computers for this are the private virtual systems (VPS) like you can buy on Digital Ocean for $4/month. Also, servers on the internet are better than home servers because they are designed to be accessible, where your home computer network could be behind a restrictive NAT that makes connecting to other clients impossible.

Step 1: Get a VPS on Digital Ocean

Get the cheapest one, which will have 10GB of storage ($7 for 25GB), which is plenty to start out with. Once you have this machine up and running, use the access console to ssh into the machine through the web browser (or ssh if you know how to configure your keys).
Run this to install the following dependencies on the VPS.
Copy and paste this into a terminal: ```bash apt update apt install python3 python3-pip npm nodejs -y pip install magic-wormhole

Installs webtorrent components

npm install -g node-pre-gyp webtorrent-cli webtorrent-hybrid ```
Make sure that you have python installed on your own computer (Windows/MacOS/Ubuntu), because we will use it later.

Step 2: Upload your content to the VPS

Make sure that you have python installed on both your VPS and your home computer.
Next prepare the content for serving, let's call it movie.mp4. We will use magic-wormhole on both server and local computer to transfer the file, since that's the easiest way I've found it to work.

Magic Wormhole to transfer the file

Run to this on both machines: pip install magic-wormhole which will install a filetransfer cmd called wormhole
On the local machine: wormhole send movie.mp4, you will get a command to run, something like wormhole receive waddle-coffee-pancake, paste this exactly into the remote computer and the file will be uploaded to the server.

Step 3: Install webtorrent-hybrid, which will act as the seeding server

On the remote machine install the webtorrent-hybrid command: npm install -g node-pre-gyp webtorrent-cli webtorrent-hybrid and hit enter.
Once that is installed you should test seeding by using the following command:
webtorrent-hybrid seed myfile --keep-seeding --port 80 -q
And wait for the magnet uri to be printed. Save the magnet uri.
Now test this link by pasting it into instant.io and verifying that the movie loads within 10 seconds.
Congrats! Now you have a magnet uri that will work (most) everywhere. However we aren't done yet. As soon as your close your SSH session your seeding process will also be killed. To make a service which will always be alive, go to the next step.

Step 4: Using pm2 to create an always on seeder service.

Creating a system service normally requires intermediate unix admin skills. Luckily this has all been made too easy with the excellent tool called pm2. So let's install it: npm install -g pm2
In the current VPS shell, make a new file: nano ./app.js and edit it so that it has the following:
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!
pm2 start ./app.js pm2 save
That's it! To check that the service is running you can do pm2 ls and check that there is an entry for app.js.
Congrats! You now have an always on seeding service. You can confirm this by issuing a restart command to your VPS and notice both the app.js process is running using pm2 ls.

Step 5: An HTML/JS video player

Remember that magnet uri I told you to remember? You are going to use it here. Replace magneturi with yours.
   

Movie player loading....

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.

Next Steps

You could of course, create a multi-seeder tool that spawns one process per video and serve an entire library of content. This is apparently what Bitchute and PeerTube do.
Thanks to Feross for a great software stack.
Hopefuly he will be inspired to update the docs on how to run a seed server. It took me weeks to figure all this out and it seems like an important use case. Happy serving!
https://github.com/zackees/webtorrent-how-to-seed-server
submitted by ZachVorhies to WebTorrent [link] [comments]

كسسوارات الهواتف الذكية تستحق ثمنها عصا «سيلفي» وشواحن محمولة وسماعات لاسلكية متقدمة

إكسسوارات الهواتف الذكية تستحق ثمنها

عصا «سيلفي» وشواحن محمولة وسماعات لاسلكية متقدمة الثلاثاء - 6 ذو الحجة 1438 هـ - 29 أغسطس 2017 مـ رقم العدد [ 14154] 📷 شاحن محمول - عدسة إضافية للهاتف لندن: «الشرق الأوسط»
عندما تشتري لنفسك هاتفاً ذكياً جديداً، كيف يمكنك أن تستفيد من أفضل الميزات التي يقدمها؟ عليك بالإكسسوارات، كما يقول بعض الخبراء. لكل هاتف يمكن للمستخدم أن يشتريه، كثير من الأدوات المضافة التي تحسن الأداء وتتميز عن الإكسسوارات الأخرى؛ ابتداء من تحديثات سماعات الأذنين، ومكبرات بلوتوث للصوت لتعزيز صوت الموسيقى، وانتهاء بالأغطية التي تحمي الهاتف من الأضرار. ولكن يجب أن تحرص أن تكون تلك الإضافات الأحدث، خصوصا أن الخيارات المتاحة كثيرة. وهنا بعض النصائح من موقع «انغادجيت» التقني البريطاني التي ستساعد المستخدم في اختيار إكسسوارات الهواتف الذكية التي تستحق الإنفاق عليها. -- إضافات التصوير - إضافات السيلفي: تزداد شعبية الصور الذاتية (السيلفي) وصور البورتريه الشخصية أكثر فأكثر، مما حثّ مصنعي الهواتف الذكية على التركيز أكثر على الكاميرات الأمامية، وكانت آخرها كاميرا «هواوي بي10» التي تقدم للعالم أول عدسة «ليكا» للسيلفي في هاتف ذكي. في حال كان المستخدم يملك عصاً للسيلفي، فيجب أن يجرب أداة «ألترا برايت سيلفي لايت»، (27 دولارا)، Ultra Bright Selfie Light، التي تثبت على أي هاتف ذكي (لها 36 من الصمامات الثنائية الضوئية LED) لتوفير إضاءة أفضل، وإشعاع أفضل لتوفير الوضوح الأكبر للصورة. - عدسات الكاميرا: في حين توفر هواتف متقدمة مثل «سوني إكس زي بريميوم» و«آيفون7» عدسات كاميرا فعالة، لمحبي التصوير الذين يرغبون في الارتقاء بصورهم دون شراء كاميرا باهظة الثمن، فإن بمقدورهم أن يستعينوا بعدسة إضافية. وتوفر عدسة «أولوكليب كور لينس»، (132 دولارا)، Olloclip Core Lens Set، لهاتف «آيفون7». و«آيفون7 بلاس»، من بينها عين السمكة، والزاوية الواسعة، والعدسات المكبرة في قطعة صغيرة تلتصق فوق كاميرا الجهاز. يذكر أن أصحاب هواتف «آندرويد» و«آيفون» يمكنهم أن يستفيدوا من نسخ مخصصة لهواتفهم. - طابعة الصور: بعد التقاط أجمل الصور، قد يرغب المستخدم في تحويلها إلى صورة عادية للذكرى، بدل تركها منسية في ألبوم الكاميرا أو ألبومات «فيسبوك». هنا يمكنه أن يستفيد من طابعة الجيب التي تأتي بحجم صغير لحملها باليد، بحجم هاتف ذكي تقريباً. من بين هذه الطابعات «إتش بي سبروكيت فوتو برينتر»، (132 دولارا)، التي تتصل بهواتف«آيفون» و«آندرويد»عبر بلوتوث ويمكن أن تستخدم لإنتاج صور بحجم 2×3 بوصة. -- أغطية وشواحن - أغطية فخمة: كثيرة هي الإكسسوارات التي يختارها المستخدم، إلا أن غطاء الهاتف لا بد أن يكون أولها. وتكثر الخيارات المتاحة من هذه الإكسسوارات؛ من تلك المضادة للمياه، إلى البلاستيكية الشفافة منها. ولكن في حال كان مالك الهاتف يرغب في خيار أكثر فخامة، فيمكنه أن يختار من مجموعة «باستيل»، Pastel Collection، أو تلك المصنوعة من جلد النوبوك من «سنيكهيف»، (28 دولارا)، التي تقدم له ملمسا راقياً دون أن يدفع مبالغ طائلة. هناك أيضاً الأغطية التي تأتي على شكل محفظة تتضمن جيوبا خاصة للبطاقات البنكية، وطبقة قابلة للطي، وهي متوفرة لـ«آيفون» و«آندرويد» بخيارات كثيرة. - شاحن محمول: مع إمضاء الناس مزيدا من الوقت في استخدام هواتفهم، من تحديث «إنستغرام» إلى مشاهدة مسلسلهم المفضل عبر «نيتفلكس»، لا بد أن البطارية لن تخدمهم طويلاً. لهذا السبب، يُنصح المستخدمون بالاستعانة بشاحن محمول. يوفر «إس تي كاي فاست فيول 15كي»، (66 دولارا)، STK Fast Fuel 15K، شحنة هائلة تصل إلى 15 ألف ملي أمبير في الساعة، التي تصلح لشحن الهاتف 6 مرات متتالية. كما تدعي «باكينغ كوالكوم كويك تشارج»، Packing Qualcomm Quick Charge، للتكنولوجيا أنها قادرة على شحن الهواتف الذكية 4 مرات أسرع ممن الشواحن التقليدية. -- سماعات ومكبرات - سماعات الرأس: يأتي كثير من الهواتف الذكية الحديثة والغالية مع سماعات الأذنين الخاصة بها. ولكن في حال كان المستخدم من محبي الموسيقى العالية، فلا بد من أنه سيبحث عن إكسسوار أكثر حداثة. هناك كثير من الخيارات المتوفرة التي تناسب محبي الرياضة بسبب مقاومتها التعرق وقدرتها على عزل الأصوات المحيطة خلال الجري أو في وسائل النقل المشتركة. توفر سماعة «أوديو تكنيكا»، (105 دولارات)،ATH - CKR70iS، نوعية ممتازة للصوت وبسعر معقول. تمتاز هذه السماعة بمسرعات ديناميكية رائعة للصوت، وبميكروفون صغير يتضمن أزرارا لاستقبال وإنهاء الاتصال والتحكم بالموسيقى. - مكبرات الصوت: حتى لو كانت مكبرات الصوت الموجودة في الهاتف جيدة، فإنه مكن للمستخدم أن يقدم لها دعماً، خصوصا في حال كان يحب مشاركة الموسيقى مع أصدقائه. الخيارات الأقوى متوفرة دائماً لإعدادات أكبر كالحفلات. وفي حين أن مكبرا صغيرا للجيب يمكن أن يفي بالغرض، فإن المكبرات الدائرية الصلبة تظلّ دائماً الخيار الأفضل. يتميز مكبر «جي بي إل فليب 4»، (158)، JBL Flip 4، العامل بتقنية بلوتوث، بحجم صغير قابل للحمل، ولكنه يخبئ ميزات صوتية هائلة، بالإضافة إلى 12 ساعة من الخدمة، والأفضل أنه مضاد للماء، مما يجعله مثالياً للحمل إلى جانب حمام السباحة.
اذاكنت تريد باسعار غير قابله للمنافسة سوف تجدها هنا
أضغط هنا
submitted by Familiar-Interview89 to u/Familiar-Interview89 [link] [comments]

I need help executing ssh commands in nodejs (vanilla javascript)

I need help executing ssh commands in nodejs (vanilla javascript)
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