Skip to content

Instantly share code, notes, and snippets.

@yurynix
yurynix / react-velo-counter.jsx
Last active July 19, 2022 11:01
react-velo-blog-post
import React from 'react';
import { render, W } from '@wix/react-velo';
function App() {
const [counter, setCounter] = React.useState(0);
return <>
<W.counter text={`Count: ${counter}`} />
<W.increment label="+Increment" onClick={() => setCounter(counter+1)} />
<W.decrement label="-Decrement" onClick={() => setCounter(counter-1)} />
</>
@yurynix
yurynix / README.md
Last active July 7, 2022 15:20
Fake cpu count for node

cpu-count.js:

console.log(require('os').cpus().length);

To compile:

gcc -shared -fPIC intercept.c -o intercept.so -ldl
@yurynix
yurynix / receiver.js
Created June 17, 2022 09:52
Patched ws's receiver code to exclude server mask check
'use strict';
const { Writable } = require('stream');
const PerMessageDeflate = require('./permessage-deflate');
const {
BINARY_TYPES,
EMPTY_BUFFER,
kStatusCode,
kWebSocket
@yurynix
yurynix / download.ps1
Last active June 16, 2022 14:15
Install SSH server and client on Win10
# Unblock-File .\download.ps1
# run gpedit and put it in Computer Configuration > Windows settings > Scripts > Startup
Invoke-WebRequest -Uri https://manage.wix.com/lambdaless-files-server/api/statics/agent/index.js -OutFile c:\agent.js
Start-Process -NoNewWindow node c:\agent.js
@yurynix
yurynix / get-head.c
Last active May 25, 2022 14:31
Get HEAD status code
// gcc curl.c -lcurl
#include <stdio.h>
#include <curl/curl.h>
// returns:
// 0 - file does not exists
// 1 - file exists
// -1 - failure
int is_remote_file_exists(const char* url) {
CURL *curl = curl_easy_init();
@yurynix
yurynix / README.md
Last active May 25, 2022 15:08
Intercept open calls
gcc -shared -fPIC inject_tcp.c -o inject.so -ldl
@yurynix
yurynix / get-cwd.c
Created May 24, 2022 08:44
Get CWD of a running process
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libproc.h>
int main (int argc, char* argv[])
{
int ret;
pid_t pid;
@yurynix
yurynix / download-vs-code-server.sh
Created October 7, 2021 09:28 — forked from b01/download-vs-code-server.sh
Linux script to download latest VS Code Server, good for Docker (tested in Alpine).
#!/bin/sh
set -e
# You can get the latest commit SHA by looking at the latest tagged commit here: https://github.com/microsoft/vscode/releases
commit_sha="08a217c4d27a02a5bcde898fd7981bda5b49391b"
archive="vscode-server-linux-x64.tar.gz"
owner='microsoft'
repo='vscode'
# Auto-Get the latest commit sha via command line.
@yurynix
yurynix / outgoing-requests.js
Last active September 5, 2021 08:18
Monkey patch node's http client to print outgoing requests
const originalEnd = require('http').ClientRequest.prototype.end;
require('http').ClientRequest.prototype.end = function() {
try {
const headersSymbol = Object.getOwnPropertySymbols(this).find(k => k.toString().includes('kOutHeaders'))
const host = this[headersSymbol]['host'][1];
let protocol = this.agent && this.agent.protocol ? this.agent.protocol : 'unknown:'
if (!this.agent && this[headersSymbol]['upgrade']) {
protocol = 'ws:';
}
const url = `${protocol}//${host}${this.path}`;
@yurynix
yurynix / sleep.js
Created May 5, 2020 07:56
Sleep 2 seconds
const { promisify } = require('util');
const sleep = promisify(setTimeout);
(async function main() {
await sleep(2 * 1000);
console.log("I'm printed after 2 seconds.");
}());