Skip to content

Instantly share code, notes, and snippets.

View kainjow's full-sized avatar

Kevin Wojniak kainjow

View GitHub Profile
@kainjow
kainjow / libproc_example.swift
Created November 24, 2018 20:09
Swift example of C libproc API
import Darwin
// Call proc_listallpids once with nil/0 args to get the current number of pids
let initialNumPids = proc_listallpids(nil, 0)
// Allocate a buffer of these number of pids.
// Make sure to deallocate it as this class does not manage memory for us.
let buffer = UnsafeMutablePointer<pid_t>.allocate(capacity: Int(initialNumPids))
defer {
buffer.deallocate()
#!/usr/bin/ruby
current_filename = nil
current_file = nil
# http://anthonylewis.com/2011/02/09/to-hex-and-back-with-ruby/
def hex_to_bin(s)
s.scan(/../).map { |x| x.hex }.pack('c*')
end
@kainjow
kainjow / TestWrite.cpp
Last active June 3, 2016 20:08
MSVC file pointer doesn't increase when writing to device path
#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#include <windows.h>
#include <iostream>
#include <string>
#include <vector>
#include <setupapi.h>
#include <sys/stat.h>
@kainjow
kainjow / JpegExifStripper.m
Created September 24, 2014 01:59
Strip EXIF metadata from a JPEG
//
// Created by Kevin Wojniak on 2014/9/23.
// Copyright (c) 2014 Kevin Wojniak. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
const char *inputFile = argv[1];
const char *outputFile = argv[2];
@kainjow
kainjow / arg.cpp
Last active August 29, 2015 14:00
Emulates QString's arg() behavior in C++11
// Public domain.
#include <iostream>
#include <string>
namespace {
template <typename T>
class fmt_base {
public:
@kainjow
kainjow / macdeployqt_fix_frameworks.rb
Created December 20, 2013 18:45
Adds missing Info.plist files to Qt frameworks in an OS X app.
#!/usr/bin/env ruby
# Copies missing Info.plist files for a .app's Qt frameworks installed
# from macdeployqt. Without the plists, 'codesign' fails on 10.9 with
# "bundle format unrecognized, invalid, or unsuitable".
#
# Example usage:
# ruby macdeployqt_fix_frameworks.rb /Users/me/Qt5.2.0/5.2.0/clang_64/ MyProgram.app
#
# Links: