Skip to content

Instantly share code, notes, and snippets.

@ben0x539
ben0x539 / rename.sh
Created March 20, 2022 02:06
use gh cli to rename default branch from master to main in all your repos
#!/usr/bin/env bash
set -euo pipefail
user=ben0x539
repos=(
$(
gh repo list --json name,defaultBranchRef --source \
| jq --raw-output '.[] | select(.defaultBranchRef.name == "master") | .name'
)
)
@ben0x539
ben0x539 / d18.rb
Last active December 18, 2021 10:07
def reduce(n)
while explode(n) || split(n)
end
n
end
def explode(n)
i = 0
depth = 0
while i < n.length
@ben0x539
ben0x539 / jsopts.rb
Last active October 16, 2021 11:26
pronounced jasopts
require 'json'
class Cell < Struct.new(:item); end
class Args
attr_reader :pos, :top
def initialize()
@pos = []
@top = {}
@stack = [Cell.new(@top)]
@ben0x539
ben0x539 / helper.h
Created July 26, 2021 23:33
python2 -c "print $(echo $'#include<fcntl.h>\n#define X O_CLOEXEC\n#include "helper.h\"' | gcc -E -x c - 2>&1 | grep '^\+' | tr -d '\n' )"
#if (X & (1<<0)) != 0
+ 1
#endif
#if (X & (1<<1)) != 0
+ 2
#endif
#if (X & (1<<2)) != 0
+ 4
#endif
#if (X & (1<<3)) != 0
@ben0x539
ben0x539 / fizzbuzz.c
Last active February 12, 2021 10:46
#define NUMBER *p-- = buf; itoa(i, buf); while (*buf++); --i;
#define FIZZ *p-- = "Fizz"; --i;
#define BUZZ *p-- = "Buzz"; --i;
#define FIZZBUZZ *p-- = "FizzBuzz"; --i;
void itoa(int value, char* s) {
int l;
if (value > 9999) l = 5;
else if (value > 999) l = 4;
else if (value > 99) l = 3;
#!/usr/bin/env ruby
# GPLv3 or at yr choice any later
require 'fileutils'
require 'json'
require 'open3'
require 'pp'
require 'time'
require 'uri'
@ben0x539
ben0x539 / get-docker-layers.sh
Created June 17, 2018 20:17
pull manifest + layers from a docker image with curl with progress meter visible
#! /usr/bin/env bash
set -euo pipefail
api() {
local type endpoint registry image arg url
type=$1 endpoint=$2 registry=$3 image=$4 arg=$5
url="https://$registry/v2/$image/$endpoint/$arg"
curl --config - <<<"-u $ARTIFACTORY_CREDS" -H "Accept: $type" "$url"
}
#![feature(proc_macro, drain_filter)]
#[crate = "0.1"]
extern crate failure;
#[crate = "0.2"]
extern crate structopt;
#[crate = "0.7"]
extern crate sha2;
#[crate = "0.5"]
extern crate quote;
use std::fmt;
use serde::Deserialize;
extern crate serde;
extern crate serde_json;
struct Foo;
impl<'de> Deserialize<'de> for Foo {
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
stdenv.mkDerivation rec {
name = "gnome-builder-${version}";
version = "3.25.2-a11c9dfa";
buildInputs = [
libxml2 desktop_file_utils llvm clang libgit2 gobjectIntrospection librsvg