Skip to content

Instantly share code, notes, and snippets.

@pfeilbr
pfeilbr / watch.sh
Last active January 29, 2019 16:26
example of getting file change details along with a batch marker. fswatch
# example of getting file change details along with a batch marker
# used to perform single action for "batch" for file changes
# set to `true` to echo all file changes
DEBUG=false
FILE_CHANGE_BATCH_MARKER='--file-change-batch-end--'
fswatch --batch-marker="${FILE_CHANGE_BATCH_MARKER}" -0 . | xargs -0 -n 1 -I {} echo {} | while read file_path;
do
@pfeilbr
pfeilbr / aws-reinvent-slideshare-presentations.js
Created December 2, 2018 01:25
parses aws slideshare pages for aws re:invent presentations adn generates a markdown formatted list of links with title
// run in browser (tested in chrome as snippet)
(async () => {
const baseURL = `https://www.slideshare.net/AmazonWebServices/presentations/`
let page = 1
const sleep = async (ms) => (new Promise(resolve => setTimeout(resolve, ms)))
const fetchItems = async (url) => {
const items = []
const parser = new DOMParser()
@pfeilbr
pfeilbr / safaribooksonline-extract-history.js
Created October 19, 2018 17:50
fetches all the books history from safaribooksonline.com for the logged in user and outputs as csv string
// fetches all the books history from safaribooksonline.com for the logged in user
// and outputs as csv string
// see screenshot @ https://www.evernote.com/l/AAHItduomfRPHpw03KboGWL5cof7oK1CZjgB/image.png
// run in browser console (tested in chrome)
(async () => {
class Scraper {
@pfeilbr
pfeilbr / all-processes-with-arguments.sh
Created October 12, 2018 14:06
all-processes-with-arguments print all launched processes with arguments (need sudo)
#!/usr/sbin/dtrace -C -s
#pragma D option quiet
proc::posix_spawn:exec-success,proc::__mac_execve:exec-success
{
this->isx64=(curproc->p_flag & P_LP64)!=0;
#define SELECT_64_86(x64, x86) (this->isx64 ? (x64) : (x86))
#define GET_POINTER(base, offset) (user_addr_t)SELECT_64_86(*(uint64_t*)((base)+sizeof(uint64_t)*(offset)), *(uint32_t*)((base)+sizeof(uint32_t)*(offset)))
@pfeilbr
pfeilbr / a.cpp
Last active October 6, 2018 14:34
C scratch area
// C scratch area
#include <cstdio>
#include <memory>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@pfeilbr
pfeilbr / us-banks.js
Created September 26, 2018 16:09
export list of US banks in csv
(async () => {
class Scraper {
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
@pfeilbr
pfeilbr / safari-book-to-text.js
Last active September 11, 2018 17:12
convert a safari book (safaribooksonline.com) to text in the browser
/* convert a safari book (safaribooksonline.com) to text in the browser */
/* must be logged in and on one of the pages in the book */
(async () => {
class Scraper {
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
package main
import (
"fmt"
"testing"
)
func TestSliceTypeAssertion(t *testing.T) {
fn := func(v interface{}) {
// Text color codes:
// 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
// see: http://webhome.csc.uvic.ca/~sae/seng265/fall04/tips/s265s047-tips/bash-using-colors.html
// '\u001b' is ESC (escape)
function color(s, c) {
return '\u001b[' + c + ';1m' + s + '\u001b[0m';
}
const s = `Hello ${color('World', 32)}. How are you?`