Skip to content

Instantly share code, notes, and snippets.

View Kyngo's full-sized avatar
🏠
Working from home

Arnau Martín Kyngo

🏠
Working from home
View GitHub Profile
@Kyngo
Kyngo / server.js
Created January 3, 2023 12:32
Bare-bones HTTP server in Node.js - No 'http' or 'express' used
const net = require('net');
const fs = require('fs');
const os = require('os');
const path = require('path');
const process = require('process');
const PORT = 8888;
const LOGS_PATH = path.join(os.tmpdir(), 'server.log');
const server = net.createServer((socket) => {
@Kyngo
Kyngo / template.sh
Created November 21, 2022 08:44
Proper Bash script template
#!/usr/bin/env bash
# Inspired on https://sharats.me/posts/shell-script-best-practices/
set -o errexit # if something fails, the script will halt
set -o nounset # if an unset variable is being read, the script will halt
set -o pipefail # if a command in a pipe fails, the script will halt
# Do we want to debug this script?
if [[ "${TRACE-0}" == "1" ]]; then
@Kyngo
Kyngo / sphp.sh
Created April 11, 2022 11:58
Quickly change your PHP version on Ubuntu
#!/bin/bash
if [ $# -ne 1 ]; then
echo "params: [version] (8.0, 5.6, 7.4 ...)"
exit 1
fi
COMMAND_EXISTS=`which php$1`
if [ $? -eq 0 ]; then
# editing nginx vhosts
@Kyngo
Kyngo / xboxwol.js
Created January 9, 2021 22:16
Boot an Xbox via LAN
#!/usr/bin/env node
/**
* This script crafts a magic packet for an Xbox One to boot up from the network.
* This has been tested on an Xbox One X in a sleeping state,
* it might not work if the console is totally powered off.
* No dependencies needed, just copy the script and off you go.
* You're free to use this as you wish, but consider mentioning me in your project's credits :)
*
* Example usage: ./xboxwol.js --ip=192.168.254.100 --liveid=F12345ABCDE12ABX
@Kyngo
Kyngo / LetraDNI.js
Last active May 5, 2022 13:39
Obtener la letra del DNI a través del número (NodeJS)
/**
* Programa para determinar la letra de tu DNI
* (C) 2019 Arnau Martín
*/
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
@Kyngo
Kyngo / ObjectCloner.js
Created June 13, 2019 16:00
Clone JavaScript objects and Arrays
/**
* Object and Array cloning system
* ===============================
* This basically deep clones an object and/or an array depending on its value and type.
*/
// clone an array
function arrayClone(source) {
let target = [];
source.forEach((val, idx) => {
@Kyngo
Kyngo / aws_lambda_slack_messenger.js
Last active March 18, 2019 16:06
AWS Lambda Function to send a message on Slack
// Simple slack messager for AWS Lambda
// I use it on my code to warn me if there's any runtime error.
const request = require("request");
const settings = require('./config.json');
exports.handler = (event, context, callback) => {
const options = {
method: 'POST',
url: settings.slack_webhook,
@Kyngo
Kyngo / deny_http_connections.php
Created July 24, 2018 08:32
Deny HTTP connections with PHP
<?php
if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443) {
return true;
} else {
die("Unsafe connections are not allowed!");
}
@Kyngo
Kyngo / pre-pretty.html
Last active July 23, 2018 05:18
Prettify pre tags
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Pre Prettify</title>
<script src="script.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>