Skip to content

Instantly share code, notes, and snippets.

View romyilano's full-sized avatar
😎
improving

Romy romyilano

😎
improving
View GitHub Profile
@romyilano
romyilano / javascriptReview.js
Last active August 29, 2015 14:13
quick and dirty javascript review. note the weirder stuff like the named slots arrays
function noParams() {
// function code goes here
}
// strings
// charAt()
var greeting = "Welcome to my Snowboard dungeon";
for (x = greetinglength - 1; x >= 0; x--) {
document.write(greeting.charAt(x));
}
@romyilano
romyilano / captureIt.m
Created April 22, 2015 00:04
AVFoundation - capturing a still image from video... d'oh from Apple Sample Code
// Capture a still image
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
}
@romyilano
romyilano / arraystuff.m
Created April 22, 2015 00:35
super basic sorting in NSArray from Apple Code
// https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/#//apple_ref/occ/instm/NSArray/sortedArrayUsingFunction:context:
NSInteger intSort(id num1, id num2, void *context) {
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
//: Playground - noun: a place where people can play
import UIKit
protocol DataSource {
func fetchValue() -> String?
}
protocol DataSourceCacheStrategy {
func retrieve<T>(from: [DataSource], using: DataSource -> T?) -> T?
@romyilano
romyilano / fibonacci.js
Last active August 29, 2015 14:21 — forked from nathansmith/_fibonacci.md
they like to have people write the recursive version in coding interviews, but the the iterative version is more space efficient. it looks cool! most people blow the first 30 minutes just trying to define what a fibonacci number is so learn it well. it is found in nature and art.
function fib(num) {
'use strict';
var val;
if (num < 2) {
val = num;
}
else {
val = fib(num - 1) + fib(num - 2);
@romyilano
romyilano / readme.md
Last active August 29, 2015 14:21 — forked from max-mapper/readme.md
  1. compile ffmpeg for arm https://github.com/fiorix/ffmpeg-arm
  2. create youtube 'live event'. get rtmp url + session id
  3. run this:
raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/<SESSION>

you can tweak -b and -fps to your liking. the settings above work well for 1080p. by not specifying width or height we get the full 1920x1080 resolution from the raspi camera

//
// BinaryDataScanner.m
//
// Copyright 2009 Dave Peck <davepeck [at] davepeck [dot] org>. All rights reserved.
// http://davepeck.org/
//
// This class makes it quite a bit easier to read sequential binary files in Objective-C.
//
// This code is released under the BSD license. If you use it in your product, please
// let me know and, if possible, please put me in your credits.
@romyilano
romyilano / filesave.m
Last active August 29, 2015 14:22
basic file saving stuff for iOS
// this is for saving to your directory
-(NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
}
NSString *path = [[self applicationDocumentsDirectory].path
stringByAppendingPathComponent:@"fileName.txt"];
[sampleText writeToFile:path atomically:YES
encoding:NSUTF8StringEncoding error:nil];
@romyilano
romyilano / string.m
Last active August 29, 2015 14:22
string algos in objective-c
// is there a way to make this stuff better
- (void)findDuplicateCharactersInString:(NSString *)inputString {
NSMutableDictionary *charDict = [[NSMutableDictionary alloc] init];
for (int i = 0; i < inputString.length; i++) {
// i don't think there's a way to turn char to ints easily ? unless i go to C? java has some nice stuff
NSString *iChar = [NSString stringWithFormat:@"%c", [inputString characterAtIndex:i]];
if (!charDict[iChar]) {
charDict[iChar] = @1;
} else {
NSUInteger charCount = [charDict[iChar] integerValue];