Skip to content

Instantly share code, notes, and snippets.

View fcaldarelli's full-sized avatar

Fabrizio Caldarelli fcaldarelli

View GitHub Profile
@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 / 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 / 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 / disable-autocomplete-field-form.html
Created July 13, 2018 20:18
Disable autocomplete field form
<input type="password" autocomplete="new-password">
@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 / 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 / test.html
Created June 15, 2018 21:08
Build Javascript Widget
<script type="text/javascript" src="http://mywebsite.com/widgets/initial.js"></script>
<div id="mywebsite-container"></div>
@fcaldarelli
fcaldarelli / RecyclerView.java
Created June 13, 2018 08:24
Recycler view swipe actions
RecyclerViewSwipeHelper swipeHelper = new RecyclerViewSwipeHelper(this, listView) {
@Override
public void instantiateUnderlayButton(RecyclerView.ViewHolder viewHolder, List<UnderlayButton> underlayButtons) {
underlayButtons.add(new RecyclerViewSwipeHelper.UnderlayButton(
"Delete",
0,
Color.parseColor("#FF3C30"),
new RecyclerViewSwipeHelper.UnderlayButtonClickListener() {
@Override
public void onClick(int pos) {
@fcaldarelli
fcaldarelli / NSAttributes text from html and font.m
Created May 17, 2018 15:46
NSAttributes text from html and font
var text = "<span style='color:red'>text to check</span>"
let attrStr = try! NSMutableAttributedString(
data: text.data(using: .unicode, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue],
documentAttributes: nil)
let range = NSRange(location: 0, length: attrStr.length)
attrStr.addAttribute(NSFontAttributeName, value: font!, range: range)
@fcaldarelli
fcaldarelli / radiogroup-selected-index.java
Created May 16, 2018 15:42
RadioGroup selected index
int index = rgModalita.indexOfChild(rgModalita.findViewById(rgModalita.getCheckedRadioButtonId()));