Skip to content

Instantly share code, notes, and snippets.

View fcaldarelli's full-sized avatar

Fabrizio Caldarelli fcaldarelli

View GitHub Profile
@fcaldarelli
fcaldarelli / mysqldump-without-affect-server-load.sh
Created June 20, 2018 19:13
Mysqldump without affect server load
mysqldump -u USER -p --single-transaction --quick --lock-tables=false DATABASE | gzip > OUTPUT.gz
@fcaldarelli
fcaldarelli / onesignal-resume-last-activity-when-opening-a-notification.java
Created July 6, 2018 16:20
Onesignal: Resume last Activity when opening a Notification
// Add the following code to the top of onCreate in your launcher Activity.
// ---
// By default OneSignal calls startActivity with the following intent flags:
// Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK
private static boolean activityStarted;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@fcaldarelli
fcaldarelli / disable-autocomplete-field-form.html
Created July 13, 2018 20:18
Disable autocomplete field form
<input type="password" autocomplete="new-password">
@fcaldarelli
fcaldarelli / recyclerview-vertical-space-item-decoration.java
Created July 26, 2018 22:06
RecyclerView Vertical Space Item Decoration
public class VerticalSpaceItemDecoration extends RecyclerView.ItemDecoration {
private final int verticalSpaceHeight;
public VerticalSpaceItemDecoration(int verticalSpaceHeight) {
this.verticalSpaceHeight = verticalSpaceHeight;
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
@fcaldarelli
fcaldarelli / atom_docker_xdebug.txt
Last active August 12, 2018 15:30
Configure Atom, Docker, XDebug
I'll use port 9005 instead standard 9000 to avoid conflicts with other applications.
Client Side (Host with Atom):
1) Download php-debug
2) Configure php-debug : Server: 10.254.254.254 - Port: 9005 - Pathmaps : add "/" at the end of path to include all subfolders
3) Enable php-debug panel inside Atom with CTRL+ALT+D (or clicking bottom left button "PHP Debug"
4) Make lo0 alias: ifconfig lo0 alias 10.254.254.254
@fcaldarelli
fcaldarelli / uiview-from-nib.swift
Created August 14, 2018 23:29
UIView from nib
extension UIView {
class func fromNib<T: UIView>() -> T {
return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![0] as! T
}
}
//Then call it like this:
let myCustomView: CustomView = UIView.fromNib()
//..or even:
@fcaldarelli
fcaldarelli / file_provider_paths.xml
Created September 7, 2018 13:05
Uri file android target >= api 24
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
@fcaldarelli
fcaldarelli / add-properties-swift-extensions.swift
Created September 7, 2018 22:07
Add properties to swift extensions
typealias IMG_VIEW_REQUESTS_TYPE = [ UIImageView : [String] ]
private struct AssociatedKey {
static var imgViewRequests = "imageCache_imgViewRequests"
}
var imgViewRequests : IMG_VIEW_REQUESTS_TYPE {
get {
return objc_getAssociatedObject(self, &AssociatedKey.imgViewRequests) as! SmartSingleton.IMG_VIEW_REQUESTS_TYPE
}
@fcaldarelli
fcaldarelli / apache2-allow-access-to-password-protected-folder.conf
Created September 25, 2018 19:53
apache2 allow access to password protected folder
<Directory "/path-to-protected">
AuthType Basic
AuthName "auth"
AuthUserFile "/auth-user-file-path"
require valid-user
SetEnvIf Request_URI "path-to-allow" allowed_restricted
Order allow,deny
@fcaldarelli
fcaldarelli / GZipLogginInterceptor.java
Created November 27, 2018 09:05
GZip logging interceptor for OkHttp and Retrofit
package myapp;
import java.io.IOException;
import java.nio.charset.Charset;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;