Skip to content

Instantly share code, notes, and snippets.

View fcaldarelli's full-sized avatar

Fabrizio Caldarelli fcaldarelli

View GitHub Profile
@fcaldarelli
fcaldarelli / afnetworking-image-download-self-signed-ssl.m
Created May 13, 2018 08:08
AFNetworking image downloader self-signed ssl
AFHTTPSessionManager *sessionManager = [AFImageDownloader defaultInstance].sessionManager;
sessionManager.securityPolicy.allowInvalidCertificates = YES;
sessionManager.securityPolicy.validatesDomainName = NO;
@fcaldarelli
fcaldarelli / mysql-remove-duplicates.sql
Last active May 8, 2018 14:30
Mysql remove duplicates
### SHORT WAY
DELETE n1 FROM names n1, names n2 WHERE n1.id > n2.id AND n1.name = n2.name
### FAST WAY
-- Create temporary table
CREATE TABLE temp_table LIKE table1;
-- Add constraint
ALTER TABLE temp_table ADD UNIQUE(category, image_set_id);
@fcaldarelli
fcaldarelli / plesk-allow-subfolder-access-in-protected-folder.conf
Last active May 8, 2018 12:46
Plesk allow subfolder access in protected folder
# 1. Inside Websites And Domains & > Apache & nginx Settings
<Directory "/var/www/vhosts/sfmobile.it/devtat.sfmobile.it">
SetEnvIf Request_URI "frontend_cro/img/email-template" allowed_restricted
Order Deny,Allow
Deny from all
Allow from env=allowed_restricted
Satisfy any
</Directory>
@fcaldarelli
fcaldarelli / hybrid-encryption.sh
Created May 3, 2018 19:31
Hybrid symmetric-asymmetric encryption for large files
####### STEP 1
cd local
openssl genrsa -out keyfile.key 4096
openssl rsa -in keyfile.key -pubout -out keyfile.pub
cp keyfile.pub ../remote/
####### STEP 2 -Encrypt
#!/bin/bash
file=$1
@fcaldarelli
fcaldarelli / uialertcontroller-centered-in-ipad.m
Last active March 28, 2020 02:52
UIAlertController centered in iPad
UIPopoverPresentationController *popPresenter = ac.popoverPresentationController;
popPresenter.sourceView = self.view;
popPresenter.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0);
popPresenter.permittedArrowDirections = 0;
@fcaldarelli
fcaldarelli / run-docker-ui-app-on-mac.md
Created March 6, 2018 22:28
Run UI Docker app on Mac
@fcaldarelli
fcaldarelli / ApplicationLifecycleHandler.java
Created November 13, 2017 00:04
Check background/foreground status for Android App
import android.app.Activity;
import android.app.Application;
import android.content.ComponentCallbacks2;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
/**
* Created by Fabrizio on 13/11/17.
*/
@fcaldarelli
fcaldarelli / show_email_account_plesk.sh
Created October 6, 2017 12:55
Show email account plesk
/usr/local/psa/admin/sbin/mail_auth_view
@fcaldarelli
fcaldarelli / sync_tinymce_hidden_textarea.js
Last active October 4, 2017 20:21
When you include TinyMCE in form, you have to sync TinyMCE content with hidden textarea, because it won't be done automatically
tinymce.init({
selector: "textarea",
setup: function (editor) {
editor.on('change', function () {
editor.save();
});
}
});
@fcaldarelli
fcaldarelli / upgrade node.sh
Created December 21, 2016 22:04
Upgrade NodeJS
Upgrade node:
1. sudo npm cache clean -f
2. sudo npm install -g n
3. sudo n stabl