Skip to content

Instantly share code, notes, and snippets.

View jlcampana's full-sized avatar
:octocat:
emu emu emu...

Jose Luis Campaña jlcampana

:octocat:
emu emu emu...
View GitHub Profile
@jlcampana
jlcampana / background_queue.m
Created March 18, 2014 08:47
Background queue dispatch
dispatch_queue_t _noFutureQueue;
//...
_noFutureQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
dispatch_sync(_noFutureQueue, ^{
//...
});
@jlcampana
jlcampana / NSString+MD5.m
Created March 13, 2014 15:41
Category that implements MD5
#import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (MD5)
- (NSString *)MD5String {
const char *cstr = [self UTF8String];
unsigned char result[16];
CC_MD5(cstr, strlen(cstr), result);
return [NSString stringWithFormat:
@jlcampana
jlcampana / delete_file.m
Created March 7, 2014 15:30
Borrar un fichero
@property (SDDispatchQueueSetterSementics, nonatomic) dispatch_queue_t ioQueue;
//...
_ioQueue = dispatch_queue_create("com.currycat.files", DISPATCH_QUEUE_SERIAL);
//...
if (path) {
dispatch_async(self.ioQueue, ^{
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
});
}
@jlcampana
jlcampana / afconvert_wavtocaf.sh
Created February 3, 2014 11:29
Script to convert WAV files to CAF to reproduce on iOS
##
## Shell script to batch convert all files in a directory to caf sound format for iPhone
## Place this shell script a directory with sound files and run it: 'sh afconvert_wavtocaf.sh'
## Any comments to '[email protected]'
##
for f in *.wav; do
if [ "$f" != "afconvert_wavtocaf.sh" ]
then
afconvert -f caff -d ima4 $f
@jlcampana
jlcampana / jvc.sh
Created January 29, 2014 16:20
Get a javascript runtime on terminal (OSX)
sudo ln -s /System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc /usr/bin
@jlcampana
jlcampana / htmlDate2Database.php
Created January 21, 2014 12:26
Transform a date value retrieved from POST form to store with an ORM
$fechaFromUI = $req->post('selected_date');
$date = DateTime::createFromFormat('d/m/Y', $fecha);
$fechaToStoreOnDatabase = $date->format('Y-m-d');
@jlcampana
jlcampana / retina.m
Created January 21, 2014 10:44
Detect retina display
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
// Retina display
} else {
// non-Retina display
}
@jlcampana
jlcampana / rotation.m
Created December 5, 2013 14:24
Permitir rotación dependiendo si es iPad o iPhone
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return YES;
}
else
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@jlcampana
jlcampana / api.php
Created November 29, 2013 20:47
Llamada AJAX POST enviando json y recibiendo json en el response con Slim PHP
<?php
// header('Cache-Control: no-cache, must-revalidate');
// header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// header('Content-type: application/json');
define('PETICION_OK' , 200);
define('PETICION_NO_AUTORIZADO' , 401);
//Login
@jlcampana
jlcampana / dismiss click outside.js
Created November 27, 2013 10:07
Ocultar div si se pulsó fuera
//Hacemos dismiss si el menú está visible y se pulsó fuera
$(document).mouseup(function (e)
{
var container = null;
if($('#menu_settings').is(":visible"))
{
container = $('#menu_settings');
}
if (container!=null && !container.is(e.target))