Skip to content

Instantly share code, notes, and snippets.

@DucHM
DucHM / main.dart
Created March 4, 2020 08:47 — forked from netsmertia/main.dart
flutter image drawing in canvas
import 'package:flutter/material.dart';
import 'dart:ui' as ui;
import 'package:flutter/services.dart' show rootBundle;
import 'dart:async';
import 'dart:typed_data';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@DucHM
DucHM / BackgroundFetch.swift
Created February 11, 2020 08:29 — forked from RameshRM/BackgroundFetch.swift
Swift Background Fetch
Step 1: Enable capabilities "background fetch"
Step2 : Setup AppDelegate.swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let settings = UIUserNotificationSettings(forTypes: UIUserNotificationType.Alert, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
return true;

Intercom user_hash

Remember that your secret key should never be exposed to the public

  • So Javascript code below should only be used for testing unless modified and used to run on a server
@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

@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 / 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+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 / 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 / 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 / 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