Skip to content

Instantly share code, notes, and snippets.

View a7md0's full-sized avatar

Ahmed Naser a7md0

View GitHub Profile
@a7md0
a7md0 / TableSchema.cs
Last active April 30, 2021 17:50
Parse SqlDataReader.GetSchemaTable into useable object
using System;
using System.Data;
using System.Collections.Generic;
public class TableSchema {
private Dictionary<string, TableSchemaColumn> columns;
public TableSchema(DataTable dataTable) {
this.columns = new Dictionary<string, TableSchemaColumn>();
@a7md0
a7md0 / BitLockerDrive.bat
Created January 19, 2022 16:35
Lock/unlock BitLocker encrypted drive script
@set DRIVE=%1
@manage-bde -status %DRIVE% | find "Lock Status:" | find "Locked" > nul2
@if "%ERRORLEVEL%"=="0" (
@manage-bde -unlock -pw %DRIVE%
) else (
@manage-bde -lock -ForceDismount %DRIVE%
)
@manage-bde -status %DRIVE% | find "Lock Status:" | find "Unlocked" > nul2
@a7md0
a7md0 / connectivity_cubit.dart
Created January 19, 2022 16:40
Flutter connectivity cubit
import 'package:bloc/bloc.dart';
import 'package:connectivity/connectivity.dart';
part 'connectivity_state.dart';
class ConnectivityCubit extends Cubit<ConnectivityState> {
ConnectivityCubit() : super(const ConnectivityInitial()) {
final connectivity = Connectivity();
connectivity.checkConnectivity().then(_onConnectivityChanged);
connectivity.onConnectivityChanged.listen(_onConnectivityChanged);
@a7md0
a7md0 / example.dart
Created May 2, 2022 19:17
Custom HTTP exceptions with DioError factory constructor
final httpClient = Dio()..options.baseUrl = 'https://example.com';
try {
var response = await httpClient.post(
'/auth/signup',
data: values,
);
if (response.data == null) {
throw const EmptyResponseException(); // Manually throw the exception