Skip to content

Instantly share code, notes, and snippets.

View mchirico's full-sized avatar
💭
Kubernetes... API Server Development

Mike Chirico mchirico

💭
Kubernetes... API Server Development
View GitHub Profile
@mchirico
mchirico / sub.awk
Created March 1, 2013 23:35
Quick awk script with substr and NF
/<event date=/{ TIME=substr($0,13,15)}
{if (NF>5)
printf("%s,%s,%s,%s,%s,%s,%s,\"%s %s %s\"\n",TIME,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10)}
@mchirico
mchirico / example.awk
Last active December 14, 2015 10:59
Simple awk with split, variable NF and NR
# Example AWK script
# echo -e '1 2 3\n4 5 6\n10.11.12'| awk -v DATE=$(date "+%m%d%y") -f t1.awk
#
/[0-9]*\.[0-9]*\./ { n=split($1,a,"."); print n " values in s" }
{
if (NR==1) {print $1 " Rec number: " NR " Fields " NF}
}
@mchirico
mchirico / funcptr.c
Created March 22, 2013 22:28
An example of a function pointer in C
#include <stdio.h>
#include <stdlib.h>
double Plus (double a, double b) { return a+b; }
double Mult (double a, double b) { return a*b; }
double Minus (double a, double b) { return a-b; }
double Div (double a, double b) { return a/b; }
void SF(double a, double b, double (*ptF)(double, double))
{
@mchirico
mchirico / myencrypt
Created March 30, 2013 14:10
Example bash command to encrypt a whole directory. The example decrypt is also shown, but commented out.
#!/bin/bash
#
#
# Replace Pa33Word with something more secure
PASSWORD=Pa33Word
DIRECTORY=secretBooks
#
#
tar -zcf - ${DIRECTORY}|openssl des3 -salt -k ${PASSWORD} | dd of=${DIRECTORY}.tar.gz.des3
#
@mchirico
mchirico / .fetchrc
Created April 1, 2013 14:38
The following is a sample .fetchmailrc for accessing Gmail remotely with ssl.
#
#
# Sample /Users/mchirico/.fetchmailrc file for 2 Gmail accounts
#
# Check mail every 90 seconds
set daemon 90
set syslog
set postmaster mchirico
#set bouncemail
#
@mchirico
mchirico / gist:5301465
Created April 3, 2013 14:00
Working https call in Objective-C for iOS
int myURLget() {
NSString *urlAsString = @"https://mchirico.appspot.com";
urlAsString = [urlAsString stringByAppendingString:@"?param1=First"];
urlAsString = [urlAsString stringByAppendingString:@"&param2=Second"];
NSURL *url = [NSURL URLWithString:urlAsString];
@mchirico
mchirico / eatblob.c
Last active October 11, 2023 04:34
Eat Blob: Example program that both reads binary data into a SQLite database, and demonstrates writing that data out.
/*
The MIT License (MIT)
Copyright (c) 2013 Mike Chirico mchirico@gmail.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
@mchirico
mchirico / mmap.c
Last active February 28, 2023 05:29
An example of mmap where data is modified in the file. This version currently compiles on Mac OSX.
/*
An example of mmap where data is modified in the file. This
version currently compiles on Mac OSX.
References:
Advanced Programming in the UNIX® Environment, Third Edition
By: W. Richard Stevens; Stephen A. Rago
Publisher: Addison-Wesley Professional
@mchirico
mchirico / mymm.m
Created April 4, 2013 22:35
Quick Hack Objective-C, just to see if it works, which it does.
//
// cwxstatViewController.m
// mymm
//
// Created by Mike Chirico on 4/4/13.
// Copyright (c) 2013 Mike Chirico. All rights reserved.
//
#import "cwxstatViewController.h"
package main
import (
"encoding/json"
"fmt"
"log"
"os/exec"
"bytes"
"reflect"
)