Skip to content

Instantly share code, notes, and snippets.

View niklasberglund's full-sized avatar

Niklas Berglund niklasberglund

  • Klurig
  • Gothenburg, Sweden
View GitHub Profile
@niklasberglund
niklasberglund / String+md5.swift
Created December 9, 2016 07:26
String md5 extension for Swift 3
//
// Based on https://gist.github.com/finder39/f6d71f03661f7147547d
// NOTE: There's no CommonCrypto module for Swift. To make the import CommonCrypto line work do something like what's described in http://stackoverflow.com/a/29189873/257577
//
import CommonCrypto
extension String {
/**
Get the MD5 hash of this String

Keybase proof

I hereby claim:

  • I am niklasberglund on github.
  • I am niklasb (https://keybase.io/niklasb) on keybase.
  • I have a public key whose fingerprint is CC9F 8745 2524 4857 CC68 677A FC4E 552D E675 EC15

To claim this, I am signing this object:

This fork makes the code run on Mac OS X.

This Gist is about how I use PyAudio, NumPy, and Matplotlib to plot freqency spectrum of system sound or microphone.

You can read this blog post for more detail.

@niklasberglund
niklasberglund / gist:834763c27ed3404fcd5f
Created September 19, 2014 15:09
Example of how to get iOS device IP address. Modified version of function at http://zachwaugh.me/posts/programmatically-retrieving-ip-address-of-iphone/ (also works on OS X)
#include "TargetConditionals.h"
#include <ifaddrs.h>
#include <arpa/inet.h>
+ (NSString *)deviceIPAddress
{
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;
@niklasberglund
niklasberglund / cocoapods_prepare_commands_paths.sh
Created September 13, 2014 17:32
Example of how you can get project dir and file path in a podspec's prepare_command
# Get project directory path
current_pwd="$PWD"
project_dir=`cd "../../"; pwd`
cd "$current_pwd"
# Get .xcodeproj file path (yes I know it's not a file)
project_file=`find "$project_dir" -maxdepth 1 -name "*.xcodeproj" | tail -1`
@niklasberglund
niklasberglund / add_lib_with_xcodeproj.rb
Created September 13, 2014 08:17 — forked from onevcat/add_lib_with_xcodeproj.rb
Example of how to use the ruby gem xcodeproj to add a library to the Frameworks group of a project. Forked and updated to work with updated version of xcodeproj.
require 'xcodeproj'
project_path = "your_project_path";
# Create project object
project = Xcodeproj::Project.new(project_path);
lib_path = "your_lib_path";
# Add the lib file as a reference
libRef = project['Frameworks'].new_file(lib_path);
@niklasberglund
niklasberglund / NSData+gzip.h
Created May 10, 2013 08:40
NSData category adding gzip functionality. Extracted from http://cocoadev.com/wiki/NSDataCategory
#import <Foundation/Foundation.h>
@interface NSData (gzip)
- (NSData *)gzipInflate;
- (NSData *)gzipDeflate;
@end