Skip to content

Instantly share code, notes, and snippets.

View scratchoo's full-sized avatar
🎯
Focusing

scratchoo

🎯
Focusing
View GitHub Profile
@scratchoo
scratchoo / NetworkingFirecracker.md
Created June 3, 2024 19:33 — forked from s8sg/NetworkingFirecracker.md
Networking with Firecracker

Create Bridge interface on the host and give internet access

sudo ip link add name br0 type bridge
sudo ip addr add 172.20.0.1/24 dev br0
sudo ip link set dev br0 up
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables --table nat --append POSTROUTING --out-interface enp3s0 -j MASQUERADE
sudo iptables --insert FORWARD --in-interface br0 -j ACCEPT

Create a tap device and link to the bridge

@scratchoo
scratchoo / shell_execute.rb
Created May 21, 2024 21:49 — forked from troelskn/shell_execute.rb
Running a shell subprocess is surprisingly hard in ruby
require "open3"
def execute_shell(command, verbose: false)
Rails.logger.info "[SHELL] #{command}"
# see: https://nickcharlton.net/posts/ruby-subprocesses-with-stdout-stderr-streams.html
# see: http://stackoverflow.com/a/1162850/83386
output = []
Open3.popen3(command) do |stdin, stdout, stderr, thread|
# read each stream from a new thread
@scratchoo
scratchoo / apt_wait.sh
Created January 9, 2024 13:41 — forked from tedivm/apt_wait.sh
A BASH function to wait for `apt` to finish and release all locks.
#!/usr/bin/env bash
apt_wait () {
while sudo fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
sleep 1
done
while sudo fuser /var/lib/apt/lists/lock >/dev/null 2>&1 ; do
sleep 1
done
if [ -f /var/log/unattended-upgrades/unattended-upgrades.log ]; then
@scratchoo
scratchoo / FindReplace.json
Created October 19, 2022 12:09 — forked from zats/FindReplace.json
Alternative spellings for some emojis according to /System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/FindReplace.strings
{
"💍":"diamond | engagement ring | diamond ring | diamond rings | diamonds | engagement rings",
"🆎":"blood type AB",
"❣":"heart",
"🇱🇨":"Saint Lucia | Saint Lucian flag",
"🇮🇪":"Ireland | Irish flag",
"🇨🇮":"Côte d’Ivoire | Ivory Coast | Ivorian flag",
"💎":"diamond | gem | gemstone | jewel | diamonds | gems | gemstones | jewels",
"☠️":"skull and crossbones | poison | poisonous",
"👩‍💻":"technology worker | tech worker | technologist | techie | IT worker | Apple genius | woman in technology | woman tech worker | woman technologist | woman IT worker | woman in IT | woman Apple genius",
Model.where(:date_column => date)
Model.where('extract(year from date_column) = ?', desired_year)
Model.where('extract(month from date_column) = ?', desired_month)
Model.where('extract(day from date_column) = ?', desired_day_of_month)
@scratchoo
scratchoo / connectHTMLelements_SVG.png
Created March 22, 2022 13:33 — forked from alojzije/connectHTMLelements_SVG.png
Connect two elements / draw a path between two elements with SVG path (using jQuery)
connectHTMLelements_SVG.png
@scratchoo
scratchoo / range_selection_save_restore.js
Created November 25, 2021 15:32 — forked from nmanikiran/range_selection_save_restore.js
Range and selection marker-element-based save and restore
/**
* This is ported from Rangy's selection save and restore module and has no dependencies.
* Copyright 2019, Tim Down
* Licensed under the MIT license.
*
* Documentation: https://github.com/timdown/rangy/wiki/Selection-Save-Restore-Module
* Use "rangeSelectionSaveRestore" instead of "rangy"
*/
var rangeSelectionSaveRestore = (function() {
var markerTextChar = "\ufeff";
@scratchoo
scratchoo / animate-browser-title.js
Created April 4, 2021 00:43 — forked from mbohanon/animate-browser-title.js
Animate title text when page tab is not active in browser (onblur), this is NOT a marquee. To see example visit http://SHEmedia.us
//Here's an eye catching example to get your visitors back when your web page tab is not active within the browser (onblur). This script will animate the original title text with an intro, the original title text is restored when the tab is returned to active state (focus). When the tab is clicked the original page title is restored. For social media sharing it is highly recommended to include the original page title text with the prefaced animated text (onblur).
//Created by SHEmedia.us
$(function() {
var origTitle, animatedTitle, timer;
function animateTitle(newTitle) {
var currentState = false;
origTitle = document.title; // save original title
require 'rubygems'
require 'faraday'
require 'socksify'
require 'socksify/http'
require 'awesome_print'
# This is a SOCKS monkey patch for Faraday, with example use/unit test.
# Notes:
# * It is altered to work with SOCKS5 authentication.
# * net_http_class must return a Faraday::Adapter::NetHttp instance.