Skip to content

Instantly share code, notes, and snippets.

View query_sixel.c
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
struct termios initial_term_params;
// Check if both stdin and stdout are TTYs.
void check_stdio() {
View colors256.rb
#!/usr/bin/ruby
256.times do |color|
if color < 7 || (color > 15 && (color - 16) % 36 < 18)
fg = 231
else
fg = 0
end
print "\e[38;5;#{fg};48;5;#{color}m #{color.to_s.rjust(3)} \e[m"
View simple-regexp.swift
import Foundation
let data = "aaa 11-22 bbb 33-44 ccc"
let regex = try! NSRegularExpression(pattern: #"\d+-\d+"#)
let range = NSRange(data.startIndex..., in: data)
regex.enumerateMatches(in: data, options: [], range: range) { (match, _, _) in
print(data.substring(with: match!.range))
}
View pcmpestrm.rs
use std::arch::x86_64 as S;
fn main() {
let data: &[u8; 16] = b"1e0b98cfa67ebe20";
let pattern: &[u8; 16] = b"b98.............";
let mask;
unsafe {
let v0 = S::_mm_loadu_si128(data.as_ptr().cast());
View invert-lightness.sh
convert input.png -colorspace hsl -channel lightness -negate output.png
View upper.md

to upper

$ gcc -O3 -Wall -Wextra upper.c -o upper-c

$ rustc -O upper.rs -o upper-rs

$ find /usr/bin/ -type f -exec strings {} + > /tmp/ascii

$ tr [[:lower:]] [[:upper:]] < /tmp/ascii | md5sum
View change-volume-ffmpeg.sh
#!/bin/bash
ffmpeg -ss 4:00:00 -i INPUT.webm -filter:a volume=0.5 half-volume.webm
ffmpeg -i INPUT.webm -t 4:00:00 -c copy start.webm
cat > files <<EOF
file 'start.webm'
file 'half-volume.webm'
EOF
View find_seqs_iterator.rs
struct Seqs<I> {
iter: I,
}
impl<'a, I: Iterator<Item = &'a u8>> Iterator for Seqs<std::iter::Enumerate<I>> {
type Item = (usize, usize);
fn next(&mut self) -> Option<Self::Item> {
// Jump to first byte '1'
let start = loop {
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
}