Skip to content

Instantly share code, notes, and snippets.

View Indy9000's full-sized avatar
🏠
Working from home

Indy M. Indy9000

🏠
Working from home
View GitHub Profile
@Indy9000
Indy9000 / donut-chart-widget.dart
Created May 31, 2021 15:40
animated-donut-chart-03
class DonutChartWidget extends StatefulWidget {
final List<DataItem> dataset;
DonutChartWidget(this.dataset);
@override
_DonutChartWidgetState createState() => _DonutChartWidgetState();
}
class _DonutChartWidgetState extends State<DonutChartWidget> {
@override
Widget build(BuildContext context) {
@Indy9000
Indy9000 / main.dart
Created May 31, 2021 15:29
animated-donut-chart-02
void main() {
runApp(MyApp());
}
const pal = [0xFFF2387C, 0xFF05C7F2, 0xFF04D9C4, 0xFFF2B705, 0xFFF26241];
class MyApp extends StatelessWidget {
final List<DataItem> dataset = [
DataItem(0.2, "Comedy", Color(pal[0])),
DataItem(0.25, "Action", Color(pal[1])),
@Indy9000
Indy9000 / dataitem.dart
Created May 31, 2021 15:24
animated-donut-chart-01
class DataItem {
final double value;
final String label;
final Color color;
DataItem(this.value, this.label, this.color);
}
@Indy9000
Indy9000 / flutter-auto-scroll-listview-to-end.dart
Created May 16, 2021 20:11
Flutter auto scroll a listview to the bottom
import 'dart:async';
import 'package:flutter/material.dart';
class Test extends StatefulWidget {
@override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> {
@Indy9000
Indy9000 / text-similarity.dart
Created February 28, 2021 17:46
Text Similarity in 75 Lines of Dart
import 'dart:core';
import 'dart:math';
class Vector {
List<num> vec;
Vector(List<num> el) {
vec = el;
}
operator [](index) => vec[index];
@Indy9000
Indy9000 / autocomplete.dart
Created February 22, 2021 11:03
Auto Complete in 65 Lines of Dart
class Node {
String prefix;
List<Node> children = List<Node>();
bool _addNewChild(String rest) {
final child = Node();
var added = child.add(rest);
if (added) children.add(child);
return added;
}
@Indy9000
Indy9000 / convert-int-to-roman-numerals-and-back.py
Last active September 10, 2020 17:23
Convert an int to roman numeral and back
def toRoman(i:int)->str:
sym = ["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
num = [1000,900,500,400,100,90,50,40,10,9,5,4,1]
result = ""
while i > 0:
for j in range(len(num)):
m = i // num[j]
result += sym[j] * m
i = i % num[j]
return result
@Indy9000
Indy9000 / n-queen-problem.py
Created October 17, 2019 19:58
This function solves the N Queen problem using backtracking
# This function solves the N Queen problem using
# Backtracking. It mainly uses solveNQUtil() to
# solve the problem. It returns false if queens
# cannot be placed, otherwise return true and
# placement of queens in the form of 1s.
# note that there may be more than one
# solutions, this function prints one of the
# feasible solutions.
def solveNQ():
board = [ [0, 0, 0, 0],
@Indy9000
Indy9000 / remove-consecutive-sum-to-n.py
Created October 17, 2019 14:05
Given a linked list of integers, remove all consecutive nodes that sum up to n.
class Node():
def __init__(self, value, next=None):
self.value = value
self.next = next
# returns a node if the sum is n
def sumTo(n, node):
s = 0
while node != None:
s = s + node.value
@Indy9000
Indy9000 / my_shared_ptr.cpp
Created October 1, 2019 12:31
Implementing a simple shared_ptr class
// In C++11 we got shared pointer. The standard implementation is much more complete and robust,
// but here I show a barebones version of it to illustrate the main components.
// Behaviour: SharedPTR manages the lifetime of a pointer to a templated object
// SharedPTR can be used to share the pointed object among other SharedPTRs.
// When all of them have given up the pointed object, The SharedPTR deallocates the
// pointed object
// For this we use reference counting. And the main point is that the counter should be a shared object itself
// that would be shared among the SharedPTRs.
template<typename T>