Skip to content

Instantly share code, notes, and snippets.

View hemant3370's full-sized avatar
😃
Focusing

Hemant Singh hemant3370

😃
Focusing
View GitHub Profile
class Solution {
func letterCombinations(_ digits: String) -> [String] {
let phone: [String: String] = ["2": "abc", "3": "def", "4": "ghi", "5": "jkl", "6": "mno", "7": "pqrs", "8": "tuv", "9": "wxyz"]
var output: [String] = []
func backTrack(combination: String, next_digits: String) {
if next_digits.count == 0 {
output.append(combination)
} else {
let digit = String(next_digits[next_digits.startIndex..<next_digits.index(next_digits.startIndex, offsetBy: 1)])
let letters: String = phone[digit] ?? ""
@hemant3370
hemant3370 / ImageViewExtension.swift
Last active May 6, 2017 08:21
image loading and disk saving using alamofire
//
// ImageExt.swift
// Dabbagul
//
// Created by Hemant Singh on 06/05/17.
import Foundation
import Alamofire
extension UIImageView {
var documentsUrl: URL {
{
var address : String?
// Get list of all interfaces on the local machine:
var ifaddr : UnsafeMutablePointer<ifaddrs>?
guard getifaddrs(&ifaddr) == 0 else { return nil }
guard let firstAddr = ifaddr else { return nil }
// For each interface ...
for ifptr in sequence(first: firstAddr, next: { $0.pointee.ifa_next }) {
private void getFeeds() {
if (mRetrofit == null){
mRetrofit = RestClient.getClient();
}
apiInterface = mRetrofit.create(ApiInterface.class);
Call<FeedResponse> call = apiInterface.getFeed(Initializer.readFromPreferences(getContext(), Constants.SPKeys.authTokenKey,""));
call.enqueue(new retrofit2.Callback<FeedResponse>() {
@Override
public void onResponse(Call<FeedResponse> call, Response<FeedResponse> response) {
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
@hemant3370
hemant3370 / ThumbnailExtract.java
Created March 28, 2017 18:49
Download video thumbnail from url and cache it to disk
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaMetadataRetriever;
import android.os.AsyncTask;
import android.os.Environment;
import android.widget.ImageView;
import org.apache.commons.io.FilenameUtils;
let circlePath2 = UIBezierPath(arcCenter: CGPoint(x: self.swapBtn.frame.midX, y: self.swapBtn.frame.midY), radius: -self.frame.width/3, startAngle: CGFloat(M_PI * 2.0), endAngle: CGFloat(M_PI) , clockwise: false)
let animation2 = CAKeyframeAnimation(keyPath: "position");
animation2.duration = 0.7
animation2.repeatCount = MAXFLOAT
animation2.path = circlePath2.cgPath
animation2.repeatCount = 0
animation2.fillMode = kCAFillModeForwards
animation2.isRemovedOnCompletion = false
let circlePath = UIBezierPath(arcCenter: CGPoint(x: self.swapBtn.frame.midX, y: self.swapBtn.frame.midY), radius: -self.frame.width/3, startAngle: CGFloat(M_PI) , endAngle: CGFloat(M_PI * 2.0) , clockwise: true)
let animation = CAKeyframeAnimation(keyPath: "position");
@hemant3370
hemant3370 / collectioncellalert.swift
Created March 4, 2017 12:31
collectionview cell in popup
let alertController = UIAlertController(title:"" , message: "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", preferredStyle: UIAlertControllerStyle.actionSheet)
let view = (collectionView.cellForItem(at: indexPath)?.contentView)!.copyView()
alertController.view.addSubview(view)
let cancelAction = UIAlertAction(title: "Done", style: .cancel, handler: {(alert: UIAlertAction!) in
collectionView.reloadData()
})
alertController.addAction(cancelAction)
alertController.popoverPresentationController?.sourceView = collectionView.cellForItem(at: indexPath)
//
// HSCache.swift
// Cache
//
// Created by Hemant Singh on 10/11/16.
// Copyright © 2016 Hemant Singh. All rights reserved.
//
import UIKit
// Showing the menu action sheet
var documentMediaTypes: [String] = []
documentMediaTypes.append(String(kUTTypePDF))
documentMediaTypes.append(String(kUTTypePNG))
documentMediaTypes.append(String(kUTTypeImage))
documentMediaTypes.append(String(kUTTypeVideo))
documentMediaTypes.append(String(kUTTypeMovie))
documentMediaTypes.append(String(kUTTypeItem))