Skip to content

Instantly share code, notes, and snippets.

View fcaldarelli's full-sized avatar

Fabrizio Caldarelli fcaldarelli

View GitHub Profile
@fcaldarelli
fcaldarelli / CustomBackButtonNavBar.m
Last active October 18, 2016 13:01
Navigation bar customized back button
@implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if([self isNavBarBackButtonCustomized])
{
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"]
style:UIBarButtonItemStylePlain
@fcaldarelli
fcaldarelli / ssh-without-timeout.sh
Last active October 19, 2016 19:39
SSH connection without timeout
ssh -o ServerAliveInterval=10 -p 22 user@host
@fcaldarelli
fcaldarelli / list of installed fonts.m
Last active October 25, 2016 20:20
iOS list of installed fonts
// available fonts listed in xcode output
for (id familyName in [UIFont familyNames]) {
NSLog(@"%@", familyName);
for (id fontName in [UIFont fontNamesForFamilyName:familyName]) NSLog(@" %@", fontName);
}
@fcaldarelli
fcaldarelli / center-image-text-uibutton.m
Created October 29, 2016 09:37
Center image and text in UIButton
- (void)centerImageTextInUIButton:(UIButton*)btn
{
// set custom font
UIFont *font = [UIFont fontWithName:@"SourceSansPro-Regular" size:12];
[btn.titleLabel setFont:font];
// the space between the image and text
CGFloat spacing = 6.0;
// lower the text and push it left so it appears centered
@fcaldarelli
fcaldarelli / SquarePercentRelativeLayout.java
Created December 2, 2016 20:57
Square Percent Relative Layout
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.percent.PercentRelativeLayout;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
public class SquarePercentRelativeLayout extends PercentRelativeLayout {
public SquarePercentRelativeLayout(Context context) {
@fcaldarelli
fcaldarelli / tree.sh
Created December 17, 2016 10:12
/usr/local/bin/tree console command for mac
#!/bin/bash
SEDMAGIC='s;[^/]*/;|____;g;s;____|; |;g'
if [ "$#" -gt 0 ] ; then
dirlist="$@"
else
dirlist="."
fi
@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
@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 / 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 / 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.
*/