Skip to content

Instantly share code, notes, and snippets.

View AseemWangoo's full-sized avatar
🐝
Beeing

Aseem Wangoo AseemWangoo

🐝
Beeing
View GitHub Profile
@AseemWangoo
AseemWangoo / test_timezone.dart
Created December 20, 2022 06:22
test ffigen timezone
test('timezones', () {
final pubspecFile = File('pubspec.yaml');
final pubspecYaml = loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
final config = Config.fromYaml(pubspecYaml['ffigen'] as YamlMap);
final output = parse(config).generate();
expect(output, contains('class TimeZoneLibrary{'));
expect(output, contains('class NSString extends _ObjCWrapper {'));
expect(output, contains('static NSTimeZone? getLocalTimeZone('));
);
}
test('url_cache', () {
final pubspecFile = File('url_cache_config.yaml');
final pubspecYaml = loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
final config = Config.fromYaml(pubspecYaml);
final output = parse(config).generate();
expect(output, contains('class URLCacheLibrary{'));
expect(output, contains('static NSURLCache?getSharedURLCache('));
});
}
@AseemWangoo
AseemWangoo / log.dart
Created December 20, 2022 06:21
log snippet
void logWarnings([Level level = Level.WARNING]) {
Logger.root.level = level;
Logger.root.onRecord.listen((record) {
print('${record.level.name.padRight(8)}: ${record.message}');
});
}
@AseemWangoo
AseemWangoo / timezones.dart
Created December 20, 2022 06:20
timezone
const dylibPath='/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation';
final lib = TimeZoneLibrary(DynamicLibrary.open(dylibPath));
final timeZone = NSTimeZone.getLocalTimeZone(lib);
if (timeZone != null) {
print('Timezone name: ${timeZone.name}');
print('Offset: ${timeZone.secondsFromGMT / 60 / 60} hours');
}
@AseemWangoo
AseemWangoo / pubspec.yaml
Created December 20, 2022 06:20
pubspec ffigen
dev_dependencies:
ffigen:
name: TimeZoneLibrary
language: objc
output: "timezone_bindings.dart"
exclude-all-by-default: true
objc-interfaces:
include:
- "NSTimeZone"
headers:
@AseemWangoo
AseemWangoo / url_cache.dart
Created December 20, 2022 06:19
url cache
void main() {
const dylibPath = '/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation';
final lib = URLCacheLibrary(DynamicLibrary.open(dylibPath));
final urlCache = NSURLCache.getSharedURLCache(lib);
if (urlCache != null) {
print('currentDiskUsage: ${urlCache.currentDiskUsage}');
print('currentMemoryUsage: ${urlCache.currentMemoryUsage}');
print('diskCapacity: ${urlCache.diskCapacity}');
print('memoryCapacity: ${urlCache.memoryCapacity}');
}
@AseemWangoo
AseemWangoo / NSURLCache.dart
Created December 20, 2022 06:18
objc config
objc-interfaces:
include:
# Includes a specific interface.
- 'NSURLCache'
# Includes all interfaces starting with "NS".
- 'NS.*'
exclude:
# Override the above NS.* inclusion, to exclude NSURL.
- 'NSURL'
rename:
name: URLCacheLibrary
language: objc
output: "url_cache_bindings.dart"
exclude-all-by-default: true
objc-interfaces:
include:
- "NSURLCache"
headers:
entry-points:
- "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURLCache.h"
@AseemWangoo
AseemWangoo / create.sh
Created December 20, 2022 06:17
Create dart project
dart create ffi_2_18
## ffi_2_18 is the name of the project which will be created
@AseemWangoo
AseemWangoo / install.sh
Created December 20, 2022 06:16
Install llvm
brew install llvm