Skip to content

Instantly share code, notes, and snippets.

View alvareztech's full-sized avatar
:octocat:
Coding...

Daniel Alvarez alvareztech

:octocat:
Coding...
View GitHub Profile
@alvareztech
alvareztech / gist:3929148
Created October 22, 2012 01:03
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@alvareztech
alvareztech / Main.java
Last active December 20, 2015 07:19
My hello gist.
public class Main {
public static void main(String[] args) {
System.out.print("Hello Gist!");
}
}
@alvareztech
alvareztech / gist:6131694
Last active December 20, 2015 12:29
iOS: Label with fit size (wrap content)
label.text = @"some text";
[label sizeToFit];
@alvareztech
alvareztech / gist:6390210
Last active December 22, 2015 00:38
Parse JSON with Objective-C.
NSError *error = nil;
id jsonObject = [NSJSONSerialization
JSONObjectWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:&error];
if (jsonObject != nil && error == nil) {
NSLog(@"Successfully deserialized...");
if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;
NSLog(@"Deserialized JSON Dictionary = %@", deserializedDictionary);
} else if ([jsonObject isKindOfClass:[NSArray class]]) {
@alvareztech
alvareztech / gist:6468426
Created September 6, 2013 19:04
iOS: Lock change orientation of Controller. (Having enabled two orientations in the project summary)
// Portrait
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
// Landscape
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@alvareztech
alvareztech / gist:6526522
Created September 11, 2013 16:56
iOS: Open and close with push event ViewController. (NavigationController required)
// Open
UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerStoryboardID"];
// Or (but no use Storyboard)
CustomViewController *viewController = [[CustomViewController alloc] init]
[self.navigationController pushViewController:viewController animated:YES];
// Close
[self.navigationController popViewControllerAnimated:NO];
@alvareztech
alvareztech / gist:6530218
Last active December 22, 2015 20:59
iOS: Usage NSUserDefaults
// Read
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *session = [defaults stringForKey:@"session"];
// Write
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:session forKey:@"session"];
@alvareztech
alvareztech / gist:6537515
Created September 12, 2013 13:40
iOS: Create alert dialog. UIAlertView.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Message"
delegate:nil // o self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
@alvareztech
alvareztech / gist:6604752
Last active December 23, 2015 07:59
iOS: Validate valid Mail.
-(BOOL) NSStringIsValidEmail:(NSString *)checkString {
BOOL stricterFilter = YES; // Discussion http://blog.logichigh.com/2010/09/02/validating-an-e-mail-address/
NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:checkString];
}
// Others
@alvareztech
alvareztech / gist:6627673
Last active December 15, 2018 06:58
Android: Create Bitmap object from assets, resources, etc.
// From resource
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);
// From assets
public static Bitmap getBitmapFromAsset(Context context, String strName) {
AssetManager assetManager = context.getAssets();
InputStream istr;
Bitmap bitmap = null;
try {
istr = assetManager.open(strName);