Skip to content

Instantly share code, notes, and snippets.

@leoschweizer
leoschweizer / Heliograph-LongestClassName.m
Created January 16, 2016 12:50
Finding the longest class name in your Objective-C runtime environment with Heliograph
#import <OpinionatedC/OpinionatedC.h>
#import <Heliograph/Heliograph.h>
NSArray *classes = [HGClassMirror allClasses];
HGClassMirror *maxName = [classes max:^NSNumber *(HGClassMirror *each) {
return @(each.name.length);
}];
NSLog(@"%@", [maxName name]);
// => ___UIDocumentPickerDocumentCollectionViewControllerAccessibility_super
@leoschweizer
leoschweizer / Heliograph-LongestMethodName.m
Created January 16, 2016 12:55
Finding the longest method name in your Objective-C runtime environment with Heliograph
#import <OpinionatedC/OpinionatedC.h>
#import <Heliograph/Heliograph.h>
NSArray *classes = [HGClassMirror allClasses];
NSMutableArray *methods = [NSMutableArray array];
[classes each:^(HGClassMirror *each) {
// add the instance methods of the reflected class
[methods addObjectsFromArray:[each methods]];
// add the class methods of the reflected class
[methods addObjectsFromArray:[[each classMirror] methods]];
@leoschweizer
leoschweizer / Heliograph-MostInstancVariables.m
Created January 16, 2016 14:55
Finding the class with the most instance variables in your Objective-C runtime environment with Heliograph
#import <OpinionatedC/OpinionatedC.h>
#import <Heliograph/Heliograph.h>
NSArray *classes = [HGClassMirror allClasses];
HGClassMirror *mostInstanceVariables = [classes max:^NSNumber *(HGClassMirror *each) {
return @([[each instanceVariables] count]);
}];
NSLog(@"%@ has %lu instance Variables", mostInstanceVariables, (unsigned long)[[mostInstanceVariables instanceVariables] count]);
@leoschweizer
leoschweizer / Heliograph-LongestInheritanceChain.m
Last active January 16, 2016 15:04
Finding the class with the longest inheritance chain in your Objective-C runtime environment with Heliograph
#import <OpinionatedC/OpinionatedC.h>
#import <Heliograph/Heliograph.h>
NSArray *classes = [HGClassMirror allClasses];
HGClassMirror *longestInheritanceChain = [classes max:^NSNumber *(HGClassMirror *each) {
return @([[each allSuperclasses] count]);
}];
NSLog(@"%@ has %lu superclasses", longestInheritanceChain, [[longestInheritanceChain allSuperclasses] count]);
@leoschweizer
leoschweizer / Heliograph-CreateAndUseClass.m
Created January 17, 2016 11:56
Creating and using a class (including instance variables and methods) at runtime with Heliograph
#import <Heliograph/Heliograph.h>
static CGSize DummySizeImpl(NSObject *self, SEL cmd) {
HGInstanceVariableMirror *ivar = [[reflect(self) classMirror] instanceVariableNamed:@"_rectIvar"];
CGRect rect;
HGStructureValueMirror *value = [ivar valueIn:self];
[value readStructureValue:&rect];
return rect.size;
}

Keybase proof

I hereby claim:

  • I am leoschweizer on github.
  • I am leoschweizer (https://keybase.io/leoschweizer) on keybase.
  • I have a public key ASA2lMRDCAbzeGKYw86iqDtn-nTuhxBzbYWw7pU4tRGbeQo

To claim this, I am signing this object:

class Dashing.Ethprice extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
@accessor 'ethprice', ->
if @get('value')
price = parseFloat(@get('value'))
class Dashing.Btcprice extends Dashing.Widget
@accessor 'value', Dashing.AnimatedValue
@accessor 'btcprice', ->
if @get('value')
price = parseFloat(@get('value'))
@leoschweizer
leoschweizer / gdax-ltc.rb
Created January 16, 2018 15:31 — forked from Skeyelab/gdax-ltc.rb
GDAX Spot Price - LTC
require 'net/http'
require 'json'
require 'uri'
SCHEDULER.every '5s', allow_overlapping: false do
uri = URI.parse('https://api.coinbase.com/v2/prices/LTC-EUR/spot')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)