Skip to content

Instantly share code, notes, and snippets.

View priore's full-sized avatar

Priore priore

View GitHub Profile
@priore
priore / uiimagetext.m
Created February 28, 2016 02:59
Add text to image
//
// Created by Danilo Priore on 18/08/12.
// Copyright (c) 2012 Prioregroup.com. All rights reserved.
//
- (UIImage*)addTextToImage:(UIImage*)img text:(NSString*)text1 XPos:(int)xpos YPos:(int)ypos fontName:(NSString*)fontName fontSize:(CGFloat)fontSize fontColor:(UIColor*)fontColor {
int w = img.size.width;
int h = img.size.height;
@priore
priore / twtimeline.m
Created February 28, 2016 02:58
How to load Twitter Timeline Widget in a UIWebView
// 1. Before create a HTML file named mywidget.html and with content :
// <html>
// <head>
// <title></title>
// <script src="http://platform.twitter.com/widgets.js"> </script>
// </head>
// <body>
// <a class="twitter-timeline" height="%i" href="https://mobile.twitter.com/DaniloPriore" data-widget id="318522515175645184" data-chrome="noheader nofooter transparent" data-border-color="#cc0000" style="display:none"> </a>
// </body>
//</html>
@priore
priore / drenumerable.cs
Created February 28, 2016 02:58
DataReader AsEnumerable (LINQ) with fields name
// create a static class
public static class DataReaderExtension
{
public static IEnumerable<Dictionary<string, object>> AsEnumerable(this System.Data.IDataReader source)
{
if (source == null)
throw new ArgumentNullException("source");
while (source.Read())
{
@priore
priore / nslc.m
Last active February 28, 2016 02:51
Change value of existing NSLayoutConstraints
- (void)setConstraintValue:(CGFloat)value forAttribute:(NSLayoutAttribute)attribute animation:(BOOL)animation
{
NSArray *constraints = self.view.constraints;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d", attribute];
NSArray *filteredArray = [constraints filteredArrayUsingPredicate:predicate];
NSLayoutConstraint *constraint = [filteredArray firstObject];
if (constraint.constant != value) {
[self.view removeConstraint:constraint];
constraint.constant = value;
[self.view addConstraint:constraint];
@priore
priore / routerip.m
Last active August 25, 2016 04:20
How to get router IP address in Objective-C
#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <string.h>
#include <net/route.h>
#include <arpa/inet.h>
#define CTL_NET 4 /* network, see socket.h */
@priore
priore / AES256Class.cs
Last active February 28, 2016 02:52
AES256 Encrypt/Decrypt
//
// https://github.com/priore/SOAPEngine/blob/master/CSHARP/AES256Class.cs
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.IO;
using System.Text;
@priore
priore / 3DESClass.cs
Last active February 28, 2016 02:52
3DES Encrypt/Decrypt
//
// https://github.com/priore/SOAPEngine/blob/master/CSHARP/3DESClass.cs
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.IO;
using System.Text;
@priore
priore / validvideourl.m
Last active February 28, 2016 02:53
Check valid MPMoviePlayerController video URL
- (void)validVideoURL:(NSString*)url valid:(void(^)())valid invalid:(void(^)())invalid
{
// AFNetworking https://github.com/AFNetworking
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/vnd.apple.mpegurl", @"video/mp2t",
@"video/mov", @"video/mpv", @"video/3gp", @"video/mp4", nil];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"HEAD" URLString:url parameters:nil error:nil];
AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
@priore
priore / avplayerstall.m
Last active February 28, 2016 02:53
AVPlayer verify streaming when stalled
@interface MYPlayer : AVPlayer
{
id playerObserver;
}
- (void)play;
- (void)stop;
- (void)pause;
@end
@priore
priore / devicetype.m
Last active February 28, 2016 02:54
Detect the type of iPhone Device independent from iOS version
// Detect the type of iPhone Device independent from iOS version
CGSize size = [UIScreen mainScreen].bounds.size;
CGFloat r = size.width > size.height ? size.width / size.height : size.height / size.width;
if (r < 1.5) {
// iPad
} else if (r == 1.5) {
// iPhone 4
} else if (r > 1.5) {
// iPhone 5/6/6+
}