Skip to content

Instantly share code, notes, and snippets.

View superhard's full-sized avatar
🎯
Focusing

Artem superhard

🎯
Focusing
View GitHub Profile
@putraxor
putraxor / rich_text_view.dart
Created April 25, 2018 05:59
Flutter rich text view with clickable hyperlink
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart' as launcher;
///TODO: check performance impact bro !!!
class LinkTextSpan extends TextSpan {
LinkTextSpan({TextStyle style, String url, String text})
: super(
style: style,
@slightfoot
slightfoot / main.dart
Last active November 27, 2023 14:06
Example of using PageStorage to store data during usage of a PageView.
import 'package:flutter/material.dart';
void main() => runApp(new MainWidget());
class MainWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
@groz
groz / sync-http.swift
Created February 15, 2018 22:29
Synchronous http request in Swift
import Foundation
func query(address: String) -> String {
let url = URL(string: address)
let semaphore = DispatchSemaphore(value: 0)
var result: String = ""
let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in
result = String(data: data!, encoding: String.Encoding.utf8)!
@deepakraj27
deepakraj27 / AttachmentHandler.swift
Last active November 1, 2023 08:40
Access Camera, Photo Library, Video and File from User device using Swift 4
//
// AttachmentHandler.swift
// AttachmentHandler
//
// Created by Deepak on 25/01/18.
// Copyright © 2018 Deepak. All rights reserved.
//
import Foundation
import UIKit
import Foundation
import CoreData
public enum CodableStorage {
public enum Errors: Error {
case itemNotFound
}
public enum Group {
@Deub27
Deub27 / UIStackView+removeAll.swift
Created November 25, 2017 14:00
Remove all arranged subviews from UIStackView at once
import UIKit
extension UIStackView {
func removeAllArrangedSubviews() {
let removedSubviews = arrangedSubviews.reduce([]) { (allSubviews, subview) -> [UIView] in
self.removeArrangedSubview(subview)
return allSubviews + [subview]
}
@sharplet
sharplet / Example.swift
Created November 3, 2017 17:46
An improved wrapper for UIImagePickerController
// Here is a usage example. Refer to ImagePicker.swift below for the implementation!
// 1. Easily configure the picker
let cameraPicker = ImagePicker(sourceType: .camera)
let cropPicker = ImagePicker(sourceType: .photoLibrary, allowsEditing: true)
// Automatically includes both kUTTypeImage and kUTTypeLivePhoto
let livePhotoPicker = ImagePicker(sourceType: .photoLibrary, mediaTypes: [.livePhotos])
// 2. Use the picker
@jeffery812
jeffery812 / archieve-pre-actions.sh
Last active February 15, 2020 06:11
Remove i386/x86_64 architectures from framework
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
FRAMEWORK_NAME="YOUR-FRAMEWORK-NAME"
cd ${SRCROOT}/Pods/${FRAMEWORK_NAME}/
echo "🚀backup ${SRCROOT}/Pods/${FRAMEWORK_NAME}/${FRAMEWORK_NAME}.framework"
if [ -f "${FRAMEWORK_NAME}.zip" ]
then
//
// UnformIdentifier.swift
// ExtDownloader
//
// Created by Amir Abbas on 7/6/1396 AP.
// Copyright © 1396 AP Mousavian. All rights reserved.
//
import Foundation
import MobileCoreServices
// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)