Skip to content

Instantly share code, notes, and snippets.

View ali2236's full-sized avatar
💭
Stuff'n Things!

Ali Qanbari ali2236

💭
Stuff'n Things!
View GitHub Profile
@ali2236
ali2236 / fibonacci.c
Created October 13, 2020 09:55
fibonacci in c
long long fibonacci(long long n) {
if (n <= 1) return 1;
return fibonacci(n - 1) + fibonacci(n - 2);
}
@ali2236
ali2236 / dart_ffi.dart
Created October 13, 2020 10:04
fibonacci dart ffi
import 'dart:ffi';
// long fibonacci(int n)
typedef NativeFibonacci = Int64 Function(Int64 n);
typedef DartFibonacci = int Function(int n);
class Fibonacci {
static final dll = DynamicLibrary.open('fibonacci.dll');
@ali2236
ali2236 / table-calendar-json.dart
Created November 8, 2020 07:13
convert a json to table calendar events
import 'dart:convert';
void main() {
var jsonSource = """
{
"Events": [
{
"id": 1,
"event_name": "Cake tasting",
"event_photo": "https://dispensaries.s3.amazonaws.com/event_photo/Southern_Cali_Kush_3.jpg",
@ali2236
ali2236 / html-attr-filter.dart
Created November 8, 2020 19:34
Filters a list of html elements based on their attributes
import 'package:html/parser.dart';
void main() {
var document = parse(body);
var selectElements = document
.getElementsByClassName('hello')
.where((element) => element.attributes['data-time'] == '9112020')
.map((item) => item.text)
.toList();
@ali2236
ali2236 / exception_chaning.dart
Last active December 3, 2020 20:07
how to chain exceptions in dart.
import 'dart:async';
void main() {
runZoned(() {
try {
try {
throw 'exception 1';
} catch (e) {
throw LinkedException('exception 2',e);
}
@ali2236
ali2236 / Q28948.py
Created January 11, 2021 15:31
Quera problem solution
s = list(input())
stk = []
for c in s:
if c == '=':
if stk:
stk.pop()
else:
stk.append(c)
print(''.join(stk))
/*
* Ali Ghanbari - 970216657
* online compiler: https://dartpad.dev/a72a868f4690256e2f58f69b01823942?null_safety=true
*/
///
/// Constants
///
enum Action { Left, Right, Suck }
enum RoomState { Clean, Dirty }
/*
* Ali Ghanbari - 970216657
* online compiler: https://dartpad.dev/a69b65959d0207f02adf4e78c532f87a?null_safety=true
*/
///
/// Constants
///
enum Action { Left, Right, Suck, Idle }
enum RoomState { Clean, Dirty }
/*
* Ali Ghanbari - 970216657
* online compiler: https://dartpad.dev/b7812076139d58b2c46258c33b5e7f30?null_safety=true
*/
import 'dart:math';
const n = 8;
enum Moves { Up, Down }
final random = Random();
@ali2236
ali2236 / cannibals-missionaries.dart
Last active June 28, 2021 16:12
AI homework #3
/*
Ali Ghanbari - 970216657
online compiler: https://dartpad.dev/a2c7d1d325c61bf06df68c85235d8ae9?null_safety=true
*/
const n = 3;
enum Position { Left, Right }
enum Move { MM, M, MC, C, CC, None }
void main() {