Skip to content

Instantly share code, notes, and snippets.

View funkydevil's full-sized avatar
🤠

Kirill funkydevil

🤠
View GitHub Profile
@funkydevil
funkydevil / main.dart
Last active November 5, 2023 12:25
Replace all %@ in string
void main() {
// Define the input string with placeholders
String inputString = "Hello, %@! How are you, %@, %@?";
// Define an array of replacement strings
List<String> replacements = ["Alice", "Bob"];
print(replaceInString(inputString, replacements));
}
@funkydevil
funkydevil / index.html
Last active February 15, 2022 13:54
JS injections, SWIFT->JS, JS->SWIFT
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.block {
display: block;
width: 100%;
border: none;
background-color: #04AA6D;
@funkydevil
funkydevil / String+QR.swift
Last active November 20, 2018 09:22
qr code from string
import Foundation
extension String {
func qrCode() -> UIImage? {
if self.isEmpty { return nil }
let data = self.data(using: String.Encoding.ascii)
if let filter = CIFilter(name: "CIQRCodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
@funkydevil
funkydevil / pasteboard.txt
Last active April 7, 2017 10:34
Copy attributed string to pasteboard
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSDictionary *stringAttributes = @{
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:13],
NSForegroundColorAttributeName: [UIColor colorWithHexString:@"4C4C4C"]
};
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Text"
attributes:stringAttributes];
NSData *rtfData = [attributedString dataFromRange:NSMakeRange(0, attributedString.length)
@funkydevil
funkydevil / NSMutableAttributedString+setFontButSaveStyle.h
Last active October 24, 2017 14:29
Chage font in attributed string, but save styles
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface NSMutableAttributedString (setFontButSaveStyle)
- (void)setFontButSaveStyle:(UIFont *)font;
@end
@funkydevil
funkydevil / UILabelWithInsets.h
Created August 19, 2015 07:07
UILabel with paddings
//
// Created by Kirill Pyulzyu on 19.08.15.
// Copyright (c) 2015 Kirill Pyulzyu. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface UILabelWithInsets : UILabel
#define IS_LANDSCAPE_ORIENTATION (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
@funkydevil
funkydevil / gist:2219cbc42626a6f95eb0
Created March 30, 2015 14:48
useful define for screen and device identification (http://stackoverflow.com/a/13156390/1928161)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
@funkydevil
funkydevil / gist:8b44027ad0df6bb95017
Created March 26, 2015 11:36
Check camera access
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if(authStatus == AVAuthorizationStatusAuthorized) {
// do your logic
} else if(authStatus == AVAuthorizationStatusDenied){
// denied
} else if(authStatus == AVAuthorizationStatusRestricted){
// restricted, normally won't happen
} else if(authStatus == AVAuthorizationStatusNotDetermined){
// not determined?!
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
@funkydevil
funkydevil / gist:bfd78e167f601037f909
Created March 26, 2015 08:27
Draw a line in UIView
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
// Draw them with a 2.0 stroke width so they are a bit more visible.
CGContextSetLineWidth(context, 2.0f);
CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point