Skip to content

Instantly share code, notes, and snippets.

@realies
realies / waitForKeyElements.js
Created July 29, 2018 16:48 — forked from mjblay/waitForKeyElements.js
A utility function, for Greasemonkey scripts, that detects and handles AJAXed content.
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content. Forked for use without JQuery.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
//--- Page-specific function to do what we want when the node is found.
function commentCallbackFunction (element) {
element.text ("This comment changed by waitForKeyElements().");
@realies
realies / configure.sh
Created October 1, 2018 06:09 — forked from lukicdarkoo/configure.sh
Raspberry Pi: AP + client mode
#!/bin/sh
# The script configures simultaneous AP and Managed Mode Wifi on Raspberry Pi Zero W (should also work on Raspberry Pi 3)
# Usage: curl https://gist.githubusercontent.com/lukicdarkoo/6b92d182d37d0a10400060d8344f86e4/raw | sh -s WifiSSID WifiPass APSSID APPass
# Licence: GPLv3
# Author: Darko Lukic <[email protected]>
# Special thanks to: https://albeec13.github.io/2017/09/26/raspberry-pi-zero-w-simultaneous-ap-and-managed-mode-wifi/
MAC_ADDRESS="$(cat /sys/class/net/wlan0/address)"
CLIENT_SSID="${1}"
CLIENT_PASSPHRASE="${2}"
@realies
realies / adminer autologin
Last active April 13, 2020 21:40 — forked from iarp/adminer autologin
A way to allow direct login to adminer
<?php
$_GET["username"] = "";
$_GET["db"] = "database";
function adminer_object() {
class AdminerAutoLogin extends Adminer {
function credentials() {
return array("127.0.0.1", "username", "password");
}
function login($login, $password) {
return true;
@realies
realies / compact-messenger.user.js
Created February 7, 2020 03:40
making the messenger side-bar always narrow
// ==UserScript==
// @name Compact Messenger
// @version 0.1
// @match https://www.messenger.com/*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// ==/UserScript==
const targetCSS = document.querySelector("link[href*='FD_uqE-4yZN.css']");
GM_xmlhttpRequest({
method: "GET",
const express = require('express');
const { ApolloServer, gql } = require('apollo-server-express');
const app = express();
app.get('/', async (req, res) => {
await new Promise(resolve => setTimeout(resolve, 5000));
res.send('ok');
});
const typeDefs = gql`
@realies
realies / pts_analysis.js
Last active September 7, 2021 17:20
nodejs pts packet sequence analysis using ffprobe
const { execSync } = require('child_process');
const stdout = execSync(`ffprobe -of json -show_packets -show_streams -show_format -i ${process.argv[2]}`, { maxBuffer: 1024 * 1024 * 32 });
const { packets } = JSON.parse(stdout);
for (let i = 0; i < packets.length - 1; i++) {
const pts = Number(packets[i].pts);
const duration = Number(packets[i].duration);
const pts_next = Number(packets[i + 1]?.pts);
if (pts + duration !== pts_next) {
console.log(`timestamp issue on packet index: ${i + 1}, pts is expected to be ${pts + duration} but it is ${pts_next}`);
}
@realies
realies / upgrade.sh
Last active September 16, 2021 18:01
posix compliant script to upgrade all subfolder docker compose services
#!/bin/bash
set -ex
if [ -z "$1" ]; then
for dir in */; do [ -e "$dir" ] || continue; ./upgrade.sh "$dir"; done
exit 0
fi
cwd="$(pwd)"
cd "$1"
if [ -f Dockerfile ]; then
image=$(cat Dockerfile | awk 'tolower($1) == "from" { print $2 }')
@realies
realies / memtest.rs
Created April 11, 2023 17:19
asking chatgpt 4 to >write a rust application that will circumvent L1, L2, and L3 and test memory latency, read and write speeds
#![feature(asm)]
use std::time::Instant;
const BUFFER_SIZE: usize = 1024 * 1024 * 128; // 128 MB
fn main() {
let mut buffer = vec![0u8; BUFFER_SIZE];
let start_time = Instant::now();
unsafe { write_memory_avx(&mut buffer); }
@realies
realies / memory_speeds2.cpp
Created April 11, 2023 18:42
m1 mem speedtest
#include <iostream>
#include <chrono>
#include <cstdint>
#include <unistd.h> // for sysctl
const int64_t ARRAY_SIZE = 1024 * 1024 * 1024; // 1024 MB
const int64_t REPETITIONS = 1000;
inline void flush_cache() {
__builtin_arm_dsb(0b1111);
#include <iostream>
#include <chrono>
#include <cstdint>
#include <unistd.h>
#include <sys/sysctl.h>
#include <mach/mach_host.h>
const int64_t REPETITIONS = 5;
inline void flush_cache() {