Skip to content

Instantly share code, notes, and snippets.

@nir9
nir9 / server.c
Created November 25, 2023 16:50
Minimalist C Web Server - not for production use, only for fun :)
#include <sys/socket.h>
#include <string.h>
#include <fcntl.h>
#include <sys/sendfile.h>
#include <unistd.h>
#include <netinet/in.h>
void main() {
int s = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr = {
@joepie91
joepie91 / random.md
Last active May 7, 2024 17:10
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

@lummie
lummie / custom_time.go
Last active May 7, 2024 17:09
Golang custom date / time formats when marshalling to JSON
// CustomTime provides an example of how to declare a new time Type with a custom formatter.
// Note that time.Time methods are not available, if needed you can add and cast like the String method does
// Otherwise, only use in the json struct at marshal/unmarshal time.
type CustomTime time.Time
const ctLayout = "2006-01-02 15:04:05 Z07:00"
// UnmarshalJSON Parses the json string in the custom format
func (ct *CustomTime) UnmarshalJSON(b []byte) (err error) {
@htp
htp / curl-websocket.sh
Last active May 7, 2024 17:08
Test a WebSocket using curl.
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: example.com:80" \
--header "Origin: http://example.com:80" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
http://example.com:80/
@Skarlso
Skarlso / main.go
Created February 16, 2019 21:31
Golang SSH connection with hostkey verification
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"golang.org/x/crypto/ssh"
kh "golang.org/x/crypto/ssh/knownhosts"
@RyanBalfanz
RyanBalfanz / llm_webui.py
Created April 16, 2024 02:31
Initial LLM WebUI
import json
import urllib.parse
from dataclasses import InitVar, dataclass
from datetime import datetime, timedelta
from typing import Protocol
import httpx
import llm
import streamlit as st

Windows Development Setup

I love Linux. But the NVIDIA drivers are broken on Wayland (again), and I need to work to be able to pay my rent.

So let's dive deep into this, by configuring this nice operating system that's pinning TikTok and Candy Crush Saga to my start menu.

@barseghyanartur
barseghyanartur / convert_mysql_dump_to_postgresql_dump.md
Created June 11, 2020 14:21
Convert MySQL dump to PostgreSQL dump

Prepare database dump using mysqldump:

mysqldump -u [username] -p [databaseName] --compatible=postgresql --default-character-set=utf8 > database.sql

Clone mysql-postgresql-converter project:

git clone git@github.com:lanyrd/mysql-postgresql-converter.git
@HQarroum
HQarroum / socat-adb-forwarding.sh
Last active May 7, 2024 17:05
Using socat to forward traffic from a network interface to the loopback address on which ADB is listening.
#!/bin/bash
set -e
# Installing required packages for the Android SDK
# and the emulator.
sudo apt update -y && \
DEBIAN_FRONTEND=noninteractive sudo apt install -y --no-install-recommends \
socat \
iproute2
@dideler
dideler / bot.rb
Last active May 7, 2024 17:05
Sending a notification message to Telegram using its HTTP API via cURL
# Use this script to test that your Telegram bot works.
#
# Install the dependency
#
# $ gem install telegram_bot
#
# Run the bot
#
# $ ruby bot.rb
#