Skip to content

Instantly share code, notes, and snippets.

View TheNova22's full-sized avatar
:octocat:
Let's just play a game of Pai Sho

Jayant Sogikar TheNova22

:octocat:
Let's just play a game of Pai Sho
View GitHub Profile
@TheNova22
TheNova22 / makeGraph
Created May 12, 2021 06:02
Graph Creation Using Matrix
// vim: syntax=swift
func makeGraph(_ edges : [[Int]])->[Int:[Int]]{
var dict : [Int:[Int]] = [:]
for node in edges{
dict[node[0],default: []].append(node[1])
}
return dict
}
@TheNova22
TheNova22 / Edit Distance
Created October 31, 2020 06:27
Edit Distance
// vim: syntax=swift
func minDistance(_ word1: String, _ word2: String) -> Int {
guard word1.count > 0 && word2.count > 0 else{
return max(word1.count,word2.count)
}
let w1 = Array(word1), w2 = Array(word2), row = w2.count, col = w1.count
var dp = Array(repeating: Array(repeating: 0, count: col+1), count: row+1)
for i in 1..<dp[0].count{
dp[0][i] = i
}
@TheNova22
TheNova22 / HexToColor
Created October 6, 2020 13:07
Hex Value To Color
// vim: syntax=dart
Color hexToColor(String code) {
return new Color(int.parse(code.substring(1, 7), radix: 16) + 0xFF000000);
}
@TheNova22
TheNova22 / Readline
Last active October 7, 2020 05:12
Readline Operations
// vim: syntax=swift
let line = Int(readLine()!)!
let line1 = readLine()!.split(separator: " ").map{ Int(String($0))! }
let numbers = readLine()!.components(separatedBy: [" "]).map { Int($0)! }
@TheNova22
TheNova22 / BinHexInt
Last active October 7, 2020 05:11
Binary Hex Int
// vim: syntax=swift
extension String {
var hexaToInt : Int { return Int(strtoul(self, nil, 16)) }
var hexaToDouble : Double { return Double(strtoul(self, nil, 16)) }
var hexaToBinary : String { return String(hexaToInt, radix: 2) }
var decimalToHexa : String { return String(Int(self) ?? 0, radix: 16)}
var decimalToBinary: String { return String(Int(self) ?? 0, radix: 2) }
var binaryToInt : Int { return Int(strtoul(self, nil, 2)) }
var binaryToDouble : Double { return Double(strtoul(self, nil, 2)) }
var binaryToHexa : String { return String(binaryToInt, radix: 16) }
@TheNova22
TheNova22 / Perm
Last active October 7, 2020 05:11
Array Permutation
// vim: syntax=swift
extension Array {
func chopped() -> (Element, [Element])? {
guard let x = self.first else { return nil }
return (x, Array(self.suffix(from: 1)))
}
}
extension Array {
func interleaved(_ element: Element) -> [[Element]] {
guard let (head, rest) = self.chopped() else { return [[element]] }
@TheNova22
TheNova22 / Sliver
Last active October 7, 2020 05:11
Sliver App Bar
// vim: syntax=dart
@override
Widget build(BuildContext context) {
var width = MediaQuery.of(context).size.width;
final theme = Theme.of(context);
return Scaffold(
// ANCHOR Extended App Bar
body: NestedScrollView(headerSliverBuilder: (
BuildContext context,bool innerBox){
return <Widget>[SliverAppBar(
@TheNova22
TheNova22 / AppBar
Last active October 7, 2020 05:11
Custom App Bar
// vim: syntax=dart
PreferredSize(
preferredSize: Size(double.infinity, 100),
child: Container(
decoration: BoxDecoration(
boxShadow: [BoxShadow(
color: Colors.black12,
spreadRadius: 5,
blurRadius: 2
)]
@TheNova22
TheNova22 / Drawer Header
Created June 24, 2020 12:47
User Account Header(For Drawer)
// vim: syntax=dart
UserAccountsDrawerHeader(
accountName: Text(name),
accountEmail: Text(email),
currentAccountPicture: CircleAvatar(
backgroundColor: finder(),
child: Text(
name[0],
style: TextStyle(fontSize: 40),
),
@TheNova22
TheNova22 / Radio
Created June 24, 2020 12:46
Radio
// vim: syntax=dart
<Widget>[
Text(
'Which name would you finalise:',
),
ListTile(
title: Text(tname),
leading: Radio(value: NameSetter.presentName, groupValue: _pres, onChanged: (NameSetter val){
setState(() {
_pres = val;