Skip to content

Instantly share code, notes, and snippets.

@yurynix
yurynix / get-head.c
Last active May 25, 2022
Get HEAD status code
View get-head.c
// 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
Intercept open calls
View README.md
gcc -shared -fPIC inject_tcp.c -o inject.so -ldl
@yurynix
yurynix / get-cwd.c
Created May 24, 2022
Get CWD of a running process
View get-cwd.c
#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 Oct 7, 2021 — forked from b01/download-vs-code-server.sh
Linux script to download latest VS Code Server, good for Docker (tested in Alpine).
View download-vs-code-server.sh
#!/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 Sep 5, 2021
Monkey patch node's http client to print outgoing requests
View outgoing-requests.js
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
Sleep 2 seconds
View sleep.js
const { promisify } = require('util');
const sleep = promisify(setTimeout);
(async function main() {
await sleep(2 * 1000);
console.log("I'm printed after 2 seconds.");
}());
@yurynix
yurynix / request.js
Created Mar 24, 2020
Lightweight request using native node http.request
View request.js
/*
Usage example:
request({
url: tarballUrl,
headers: registry.headers,
dataHandler: dataBuffer => {
if (shasum) {
shasum.update(dataBuffer);
}
byteCount += dataBuffer.length;
@yurynix
yurynix / reset_dns.sh
Last active Feb 9, 2021
Reset DNS after GlobalProtect getting stuck
View reset_dns.sh
#!/bin/bash
scutil_primary_output=$(scutil << EOF
get State:/Network/Global/IPv4
d.show
EOF)
primary_interface=$(echo $scutil_primary_output | sed -n 's/.*PrimaryInterface : \([a-z0-9]*\).*/\1/p')
primary_service=$(echo $scutil_primary_output | sed -n 's/.*PrimaryService : \([A-Z0-9-]*\).*/\1/p')
#echo $primary_interface $primary_service
#exit;
View print-process.js
const processStats = await getProcessStats();
printProcessStats(processStats);
processStats.forEach(processInfo => {
console.log(`Sending SIGKILL to pid: ${processInfo.pid} exe: ${processInfo.exe}`);
process.kill(processInfo.pid, 'SIGKILL');
});
View download.js
try {
await downloadAndExtract();
} catch (ex) {
const errorMessage = ex.message;
if (errorMessage.indexOf('ENOSPC') > -1) {
console.log('Got ENOSPC! Check out df output:\n', await exec('df -h'));
}
throw ex;
}