Skip to content

Instantly share code, notes, and snippets.

Avatar

Ayose Cazorla ayosec

View GitHub Profile
View linux-syscalls.sh
git clone --depth 1 https://github.com/torvalds/linux.git
cd linux
rg --json \
--mmap \
--multiline \
'^SYSCALL_DEFINE\d+\s*?\((?s).*?\)' \
| jq -r '
select(.type == "match")
@ayosec
ayosec / code-blocks.awk
Last active Oct 31, 2020
Extract code blocks
View code-blocks.awk
# Usage:
#
# $ awk -f block.awk -v START="fn myfunc" foo.rs bar.rs | pygmentize -l rs
{
if(acc == 0) {
if($0 ~ START) {
indent = match($0, /[^[:space:]]/)
acc = $0
}
@ayosec
ayosec / playerctl-fast.sh
Created Oct 5, 2020
playerctl: skip metada to control music
View playerctl-fast.sh
#!/bin/bash
set -euo pipefail
case "${1:-}" in
next)
MEMBER=Next
;;
previous)
View WebCrypto-PBKDF2-AES-GCM.js
async function keysFromPassword(salt, password) {
let enc = new TextEncoder().encode(password);
let basekey = await crypto.subtle.importKey("raw", enc, "PBKDF2", false, ["deriveBits"]);
let keys = await crypto.subtle.deriveBits(
{
name: 'PBKDF2',
hash: 'SHA-512',
salt: salt,
iterations: 1e5
View code2html.rb
#!/usr/bin/env ruby
require "erb"
require "etc"
if ARGV.empty?
puts "Usage: #$0 files... > output.html"
exit 1
end
View bluez-headsets.sh
#!/bin/bash
MAC=01_23_45_67_89_AB
FILTER=$(paste -sd, <<FILTER
type='signal'
sender='org.bluez'
interface='org.freedesktop.DBus.Properties'
path='/org/bluez/hci0/dev_$MAC'
member='PropertiesChanged'
View list-aws-elastic-ips.sh
#!/bin/bash
export AWS_DEFAULT_REGION=${REGION:-eu-west-1}
aws ec2 describe-addresses \
--query 'Addresses[*][InstanceId, PublicIp]' \
--output text \
| while read ID IP
do
echo -en "$IP\\t"
View traits_closures.rs
trait Handler<Args> {
fn call(self) -> Result<(), ()>;
}
macro_rules! impl_for_tuple {
($($tys:ident),*) => {
impl<F, $($tys,)*> Handler<($($tys,)*)> for F
where
F: FnMut($($tys),*) -> (),
$($tys: std::str::FromStr,)*
@ayosec
ayosec / parallel-thumbnails.sh
Created Apr 12, 2020
Directory thumbnails. Avoid memory limits in ImageMagick using subprocesses.
View parallel-thumbnails.sh
#!/bin/bash
set -eu -o pipefail
CMD="$(mktemp)"
for DIR in "$@"
do
echo "set -xe; montage \\" > "$CMD"
You can’t perform that action at this time.