Skip to content

Instantly share code, notes, and snippets.

View mahmudahsan's full-sized avatar

Mahmud Ahsan mahmudahsan

View GitHub Profile
struct ContentView: View {
var body: some View {
HStack {
Text("Gender")
.font(Font.headline)
RadioButtonGroups { selected in
print("Selected Gender is: \(selected)")
}
}.padding()
}
//MARK:- Group of Radio Buttons
enum Gender: String {
case male = "Male"
case female = "Female"
}
struct RadioButtonGroups: View {
let callback: (String) -> ()
@State var selectedId: String = ""
import SwiftUI
//MARK:- Single Radio Button Field
struct RadioButtonField: View {
let id: String
let label: String
let size: CGFloat
let color: Color
let textSize: CGFloat
import SwiftUI
//MARK:- Checkbox Field
struct CheckboxField: View {
let id: String
let label: String
let size: CGFloat
let color: Color
let textSize: Int
let callback: (String, Bool)->()
struct GradientText: View {
let title: String
let colors = Gradient(colors: [Color.hexStringToColor(hex: "#FF0000"),
Color.hexStringToColor(hex: "#40B482")])
var body: some View {
RadialGradient(gradient: colors,
center: .center,
startRadius: 0,
endRadius: 300)
@mahmudahsan
mahmudahsan / swiftui_color_from_hex.swift
Created February 27, 2020 04:42
SwiftUI how to create color from hex value
extension Color {
static func hexStringToColor (hex:String, opacity: Double = 1.0) -> Color {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) != 6) {
return Color.gray
}
var rgbValue:UInt64 = 0
@mahmudahsan
mahmudahsan / swiftui_gradient_text1.swift
Created February 27, 2020 04:40
SwiftUI How to create a gradient text
import SwiftUI
extension Color {
static func hexStringToColor (hex:String, opacity: Double = 1.0) -> Color {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) != 6) {
return Color.gray
@mahmudahsan
mahmudahsan / obj-c.m
Last active February 7, 2020 05:26
Objective-C Code
const char *sqlStatement = [query UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *word = [NSString stringWithUTF8String:(char *)sqlite3_column_tcompiledStatement,
[arrayWords addObject:word];
}
}
def parse_soup_to_simple_html(self):
news_list = self.__soup.find_all(['h1', 'h2']) # h1
#print (news_list)
htmltext = '''
<html>
<head><title>Simple News Link Scrapper</title></head>
<body>
{NEWS_LINKS}
@mahmudahsan
mahmudahsan / defer.swift
Created December 22, 2017 16:44
cleanup actions using defer
func readDesc(_ desc:inout String) throws {
let newDesc = desc
defer {
desc = ""
}
throw SampleError.sample2(message: "cool error")
print(newDesc)
}
var desc = "Life is cool and play is a tool!"