Skip to content

Instantly share code, notes, and snippets.

@DucHM
DucHM / NonSwipeableViewPager.kt
Created May 4, 2018 09:30
Disable swipe View Pager Kotlin
package robert.custom.indicator
/**
* Created by robert on 2018 May 02
*/
import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.animation.DecelerateInterpolator
@DucHM
DucHM / NumberPickerDialog.kt
Created May 4, 2018 09:33
Customize Number picker dialog by Kotlin
package robert.com.unittest.customize
import android.app.AlertDialog
import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.util.Log
import android.widget.NumberPicker
/**
@DucHM
DucHM / ZoomLayout.java
Created September 4, 2019 07:22 — forked from anorth/ZoomLayout.java
Pinch-zoomable Android frame layout
package au.id.alexn;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.widget.FrameLayout;
@DucHM
DucHM / multipart.swift
Created September 21, 2019 02:43 — forked from DejanEnspyra/multipart.swift
Alamofire 4 — Multipart file upload with Swift 3 (http://theappspace.com/multipart-file-upload/)
func requestWith(endUrl: String, imageData: Data?, parameters: [String : Any], onCompletion: ((JSON?) -> Void)? = nil, onError: ((Error?) -> Void)? = nil){
let url = "http://google.com" /* your API url */
let headers: HTTPHeaders = [
/* "Authorization": "your_access_token", in case you need authorization header */
"Content-type": "multipart/form-data"
]
Alamofire.upload(multipartFormData: { (multipartFormData) in
@DucHM
DucHM / CountingFileRequestBody.java
Created October 14, 2019 02:01 — forked from eduardb/CountingFileRequestBody.java
Uploading a file with a progress displayed using OkHttp
public class CountingFileRequestBody extends RequestBody {
private static final int SEGMENT_SIZE = 2048; // okio.Segment.SIZE
private final File file;
private final ProgressListener listener;
private final String contentType;
public CountingFileRequestBody(File file, String contentType, ProgressListener listener) {
this.file = file;
@DucHM
DucHM / ShakingCollectionViewCell.swift
Created October 15, 2019 14:55 — forked from vlchapaev/ShakingCollectionViewCell.swift
Example of creating shaking collection view cell
import UIKit
protocol CellActionDelegate {
func removeCellAtIndex(_ index: Int)
}
class ShakingCollectionViewCell: UICollectionViewCell {
var shakeEnabled: Bool!
@DucHM
DucHM / UIView+Animations.swift
Created October 15, 2019 14:57 — forked from mourad-brahim/UIView+Animations.swift
Shake animation with swift
extension UIView {
func shake(duration: CFTimeInterval) {
let translation = CAKeyframeAnimation(keyPath: "transform.translation.x");
translation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
translation.values = [-5, 5, -5, 5, -3, 3, -2, 2, 0]
let rotation = CAKeyframeAnimation(keyPath: "transform.rotation.z")
rotation.values = [-5, 5, -5, 5, -3, 3, -2, 2, 0].map {
(let degrees: Double) -> Double in
let radians: Double = (M_PI * degrees) / 180.0
@DucHM
DucHM / SnappyRecyclerView.java
Created October 30, 2019 07:22 — forked from nesquena/SnappyRecyclerView.java
Snap-to-Center RecyclerView Extension
// From: http://stackoverflow.com/a/37816976
public class SnappyRecyclerView extends RecyclerView {
// Use it with a horizontal LinearLayoutManager
// Based on http://stackoverflow.com/a/29171652/4034572
public SnappyRecyclerView(Context context) {
super(context);
}
@DucHM
DucHM / UIView+Bounce
Created November 1, 2019 09:44 — forked from muukii/UIView+Bounce
UIView bounce Animation
- (void)bounceAnimation:(void (^)())completion
{
CGRect rect = self.frame;
CGRect insetRect = CGRectInset(rect, 10, 10);
self.frame = insetRect;
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.frame = rect;
} completion:^(BOOL finished) {
@DucHM
DucHM / license-badges.md
Created December 30, 2019 14:14 — forked from lukas-h/license-badges.md
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes