Skip to content

Instantly share code, notes, and snippets.

View bynect's full-sized avatar
🙄
Procrastinating

nect bynect

🙄
Procrastinating
  • Laniakea Supercluster
  • 02:57 (UTC +02:00)
View GitHub Profile

String operator

Operator Description Example
= is equal to [ $a = $b ]
== is equal to [ $a == $b ]
!= is not equal to [ $a != $b ]
> is greater than, in alphabetical order [ $a > $b ]
< is less than, in alphabetical order [ $a < $b ]
-z has zero length [ -z $a ]
-n has non-zero length [ -n $a ]
@bynect
bynect / ls.rs
Created December 18, 2020 16:51
Educational implementation of the ls command in Rust. Doesn't support globbing nor proper error handling.
pub fn main() {
// collect the command line arguments into a vector of string
let mut argv: Vec<String> = std::env::args().collect();
// if no arguments are given assume the current directory
if argv.len() < 2 {
argv.push(String::from("."));
}
// iterate over the vector of args ignoring the first argument
@bynect
bynect / echo.rs
Last active December 18, 2020 16:52
Educational implementation of the echo command in Rust.
pub fn main() {
// collect the command line arguments into a vector of string
let argv: Vec<String> = std::env::args().collect();
// iterate over the vector of args ignoring the first argument
for arg in &argv[1..] {
// ignore args starting with '-'
if !arg.starts_with("-") {
// print argument without newline
print!(
@bynect
bynect / ascii.c
Created December 30, 2020 21:08
A shell utility that prints the integer value of the given ascii characters.
/* ascii.c -- print the integer value of the given ascii chars */
/*
compilation:
cc ascii.c -o ascii
usage:
ascii your characters here [...]
*/
@bynect
bynect / strtoi.c
Created January 2, 2021 11:49
A simple implementation of string (char *) to int conversion in ISO C.
/* Naive implementation of string (char *) to int conversion in ISO C. */
int
strtoi(const char *str, unsigned int len)
{
int i, neg, num;
unsigned int val, pow;
if (str == 0 || len == 0)
@bynect
bynect / restapi.go
Last active January 24, 2021 19:51
Simple RESTful API made in Go with Mux.
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/google/uuid"
"github.com/gorilla/mux"
)
@bynect
bynect / doughnut.c
Last active January 25, 2021 09:31
A spinning doughnut made in C.
//A spinning doughnut made in C.
//Found that on a Youtube vid, very cool though.
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
int k;
@bynect
bynect / vector.h
Last active March 16, 2021 21:28
Generic vector implementation in C using preprocessor macros.
#ifndef VECTOR_H
#define VECTOR_H
#include <stdint.h>
#include <stddef.h>
#include <malloc.h>
#define VECTOR(_type) VECTOR_##_type##_t
#define VECTOR_INIT(_type, _vec) VECTOR_##_type##init(_vec)
#define VECTOR_FREE(_type, _vec) VECTOR_##_type##free(_vec)
@bynect
bynect / wgetpaste.diff
Last active June 1, 2021 12:12
Patch that adds XDG dirs to the default wgetpaste config locations.
735c735
< for f in {/etc/,~/.}wgetpaste{.d/*,}.conf; do
---
> for f in {/etc/,~/.}wgetpaste{.d/*,}.conf; do
739a740,747
> # xdg locations override everything else
> if [[ -n "$XDG_CONFIG_HOME" ]]; then
> for f in $XDG_CONFIG_HOME/{wgetpaste/,wgetpaste/.,.,}wgetpaste{.d/*,}.conf; do
> if [[ -f $f ]]; then
> source "$f" || die "Failed to source $f"
@bynect
bynect / gpg_troubleshooting.md
Last active June 3, 2021 12:04
Troubleshooting for `gpg failed to sign the data` error.

Error

You have linked GPG to git and Github, following the instructions on the documentation, but when you tried to sign a commit this message shows up:

error: gpg failed to sign the data
fatal: failed to write commit object

Try

You can track what GPG and git are trying to do with GIT_TRACE=1: