Skip to content

Instantly share code, notes, and snippets.

View dipendra-sharma's full-sized avatar

Dipendra Sharma dipendra-sharma

View GitHub Profile
@dipendra-sharma
dipendra-sharma / osx_setup.md
Created March 13, 2024 10:22 — forked from millermedeiros/osx_setup.md
Mac OS X setup

Setup Mac OS X

I've done the same process every couple years since 2013 (Mountain Lion, Mavericks, High Sierra, Catalina) and I updated the Gist each time I've done it.

I kinda regret for not using something like Boxen (or anything similar) to automate the process, but TBH I only actually needed to these steps once every couple years...

@dipendra-sharma
dipendra-sharma / rebuilder.dart
Last active March 14, 2024 09:14
A reusable Flutter widget that efficiently rebuilds when the underlying data changes, supporting various data sources like ValueListenable, Listenable.
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
typedef Selector<T, V> = V Function(T value);
typedef WidgetReBuilder<T> = Widget Function(
BuildContext context, T value, Widget? child);
class ReBuilder<T> extends StatefulWidget {
final WidgetReBuilder<T> builder;
final List<Selector<T, dynamic>> selectors;
@dipendra-sharma
dipendra-sharma / future_debouncer.dart
Last active March 13, 2024 10:14
This gist demonstrates how to implement debounce functionality in Dart using the `dart:async` library. Debounce is a technique used to delay the execution of an action until a certain amount of time has passed without any further invocations.
import 'dart:async';
class Debouncer {
final Duration delay;
Timer? _timer;
Debouncer({required this.delay});
Future<T> run<T>(Future<T> Function() action) async {
if (_timer != null) {
@dipendra-sharma
dipendra-sharma / service_locator.dart
Last active March 13, 2024 10:20
Discover a streamlined approach to dependency injection with this Dart Service Locator Gist, designed to enhance your Flutter or Dart applications. This robust pattern simplifies dependency management, promoting clean architecture and maintainable code. The ServiceLocator class empowers developers to register dependencies and retrieve service in…
class _ServiceLocator {
final Map<Type, dynamic> _singletons = <Type, dynamic>{};
final Map<Type, Function> _factories = <Type, Function>{};
// Private constructor
_ServiceLocator._();
// Public accessor
static final _ServiceLocator instance = _ServiceLocator._();
@dipendra-sharma
dipendra-sharma / interactive_viewer_with_rotation.dart
Created December 20, 2023 11:37
Implementing rotation functionality within InteractiveViewer would be highly beneficial. For those looking to incorporate similar features.
class InteractiveViewerWithRotation extends StatefulWidget {
final Widget child;
const InteractiveViewerWithRotation({super.key, required this.child});
@override
State<InteractiveViewerWithRotation> createState() =>
_InteractiveViewerWithRotationState();
}
@dipendra-sharma
dipendra-sharma / scrape-and-post-to-discourse.js
Created July 27, 2023 10:18 — forked from pnutmath/scrape-and-post-to-discourse.js
Scrape documentation and post to QnAs discourse
import fetch from 'node-fetch';
import cheerio from 'cheerio';
import { Configuration, OpenAIApi } from 'openai';
const OPENAI_API_KEY = '<YOUR_OPENAI_API_KEY>';
const DISCOURSE_SERVER_URL = '<YOUR_DISCOURSE_SERVER_URL>';
const DISCOURSE_API_KEY = '<YOUR_DISCOURSE_API_KEY>';
const DISCOURSE_POST_CREATORS = ['<CREATOR1>', '<CREATOR2>'];
const DISCOURSE_PRODUCT_MODERATORS = ['<MODERATOR1>', '<MODERATOR2>'];
const CATEGORY_ID = 1;
@dipendra-sharma
dipendra-sharma / nsd.java
Created April 5, 2023 08:00 — forked from richard1122/nsd.java
A simple example for Android NSD(network service discovery) and server socket
package com.richard1993.android.inputhack;
import android.app.Service;
import android.content.Intent;
import android.net.nsd.NsdManager;
import android.net.nsd.NsdServiceInfo;
import android.os.IBinder;
import android.util.Log;
import java.io.BufferedInputStream;
@dipendra-sharma
dipendra-sharma / axios.js
Created June 15, 2022 11:29 — forked from arvindkumarbadwal/axios.js
Axios SSL Certificate Pinning
const tls = require('tls');
const https = require('https');
const crypto = require('crypto');
const axios = require('axios');
function sha256(s) {
return crypto.createHash('sha256').update(s).digest('base64');
}
const options = {
@dipendra-sharma
dipendra-sharma / gha_workflow_dispatch.js
Created May 9, 2022 11:25 — forked from rehangit/gha_workflow_dispatch.js
Javascript injection for GHA workflow_dispatch
// ==UserScript==
// @name GHA workflow_dispatch
// @namespace https://gist.github.com/rehangit/58409fc3cca4ec7630487ac13a055b27
// @version 0.1.7
// @description Add missing info in workflow_dispatch actions
// @author Rehan Ahmad
// @match https://github.com/*/*/actions
// @match https://github.com/*/*/actions/*
// @grant none
// @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMDAiIGhlaWdodD0iMzIwIiBmaWxsPSJub25lIiBzdHJva2U9IiMwMDdmZmYiPjxjaXJjbGUgY3g9Ijk5LjUiIGN5PSI5OS41IiBzdHJva2Utd2lkdGg9IjE1IiByPSI1MCIvPjxwYXRoIGQ9Ik04NyAxMjJsMzUtMjIuNUw4NyA3N3oiIHN0cm9rZS13aWR0aD0iOCIvPjxwYXRoIGQ9Ik05OS41IDE1MmMwIDIyLjUgMCAyMi41IDk1IDIyLjAxbS05NS0xOS41MWMwIDkyLjcgMCA5Mi43IDY1IDk1IiBzdHJva2Utd2lkdGg9IjE1Ii8+PGNpcmNsZSBjeD0iMjE5LjUiIGN5PSIyNDkuNSIgc3Ryb2tlLXdpZHRoPSIxMCIgcj0iMjUiLz48cGF0aCBkPSJNMjA3IDI0OS41aDdtMTEgMGg3IiBzdHJva2Utd2lkdGg9IjgiIHN0cm9rZS1kYXNoYXJyYXk9IjQwIDQ4Ii8+PGNpcmNsZSBjeD0iMjE5LjUiIGN5PSIxNzQuNSIgc3Ryb2t
@dipendra-sharma
dipendra-sharma / Shell.java
Created January 24, 2022 13:14 — forked from ricardojlrufino/Shell.java
Run shell comands from APP as SUDO (like start ADB)
package br.com.criativasoft.eduaccess.util;
import android.util.Log;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;