Skip to content

Instantly share code, notes, and snippets.

/*
* File....... IRanalyzer.pde
* Purpose.... Records up to 128 signal changes
* Author..... Walter Anderson
* E-mail..... wandrson@walteranderson.us
* Started.... 18 May 2007
* Updated.... 18 May 2007
*
*
*/
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h> //close()
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h>// select(), fd_set, FD_* macros
/*
* Example on how to work with a non-blocking connect. Uses fixed input and
* should show all 3 situations we care about - a successful connect, a refused
* connect, and a timeout.
*
* (c) jp@devnull.cz, vlada@devnull.cz
*/
#include <sys/types.h>
#include <sys/socket.h>
@rogersguedes
rogersguedes / vm-settime.sh
Created August 15, 2019 17:28
Sets the date in a VirtualBox VM given a time offset in seconds.
#!/bin/bash
#thanks to https://winaero.com/blog/how-to-set-the-bios-date-in-virtualbox/
if [[ -z ${1} || -z ${2} ]]
then
echo ${0} " Usage:"
echo " ${0} <vm-name> <time-offset>"
echo " Example: ${0} projectVM -36000000"
exit
fi
@rogersguedes
rogersguedes / timeoffset-to.sh
Last active August 15, 2019 17:28
calculates the time between current time and a given date time.
#!/bin/bash
if [[ -z $1 ]]
then
echo $0 " Usage:"
echo " ${0} <date>"
echo " Example: ${0} 1990-09-21"
exit
fi
past_secs=$(date --date ${1} +%s)
@rogersguedes
rogersguedes / generate_toc.rb
Created August 2, 2019 11:24 — forked from albertodebortoli/generate_toc.rb
Generate Markdown TOC
#!/usr/bin/env ruby
File.open("your_file.md", 'r') do |f|
f.each_line do |line|
forbidden_words = ['Table of contents', 'define', 'pragma']
next if !line.start_with?("#") || forbidden_words.any? { |w| line =~ /#{w}/ }
title = line.gsub("#", "").strip
href = title.gsub(" ", "-").downcase
puts " " * (line.count("#")-1) + "* [#{title}](\##{href})"
@rogersguedes
rogersguedes / non-blocking-echo-server.c
Last active July 30, 2019 19:32
Socket server in C with attempt to be non blocking
/**
* Snippet from https://www.binarytides.com/multiple-socket-connections-fdset-select-linux/
*/
#include <stdio.h>
#include <string.h> //strlen
#include <stdlib.h>
#include <errno.h>
#include <unistd.h> //close
#include <arpa/inet.h> //close
#include <sys/types.h>
@rogersguedes
rogersguedes / async_dns.c
Created July 17, 2019 12:43 — forked from mopemope/async_dns.c
c-ares example
#include <ares.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
@rogersguedes
rogersguedes / audio-files-mover.sh
Created July 5, 2019 16:20
This script parses file info generated by ffmpeg and, if the first stream is an audio stream, moves to file to from $1 to $2
#!/bin/bash
# This script parses file info generated by ffmpeg and, if the first stream is an audio stream, moves to file to from
# $1 to $2
# https://www.computerhope.com/unix/bash/read.htm
find $1 -maxdepth 1 -type f -print0 |
while IFS= read -r -d '' line
do
ffmpeg -i "${line}" 2>&1 | grep --color=always "Stream #0:0[()a-z]*: Audio" > /dev/null
@rogersguedes
rogersguedes / sign.sh
Created July 2, 2019 19:08 — forked from ezimuel/sign.sh
Sign and verify a file using OpenSSL command line tool. It exports the digital signature in Base64 format.
#!/bin/bash
# Sign a file with a private key using OpenSSL
# Encode the signature in Base64 format
#
# Usage: sign <file> <private_key>
#
# NOTE: to generate a public/private key use the following commands:
#
# openssl genrsa -aes128 -passout pass:<passphrase> -out private.pem 2048
# openssl rsa -in private.pem -passin pass:<passphrase> -pubout -out public.pem