Skip to content

Instantly share code, notes, and snippets.

View shan-shaji's full-sized avatar
🧑‍💻
Coding Remotely

Shan Shaji shan-shaji

🧑‍💻
Coding Remotely
View GitHub Profile
@shan-shaji
shan-shaji / main.dart
Last active July 31, 2023 19:19
Dart-Liskov-substitution
// Liskov substitution principle
void main() {
PayPalProcessor payPalProcessor = PayPalProcessor();
VisaPaymentProcessor visaProcessor = VisaPaymentProcessor();
// Here the checkout function don't now which service it is using to process the payment.
// THe underlying implementation is hidden from the checkout function.
//
// I can add more function to the payment processor and can extend it's functionality.
checkout(payPalProcessor, 230);
@shan-shaji
shan-shaji / srp.dart
Last active July 30, 2023 16:30
Dart-SRP
# Dart-SRP
void main() {
ApiController apiRedisService = ApiController(cacheService: RedisService());
ApiController apiNodeCacheService = ApiController(cacheService: NodeCacheService());
apiRedisService.saveToCache('Hello');
apiNodeCacheService.saveToCache('Main');
}
@shan-shaji
shan-shaji / locate-platform-folder.dart
Created January 10, 2023 18:45
Dart snippet for getting commonly used locations for storage on Windows, Mac, and Linux, such as the app data directories.
import 'dart:io' show Directory, FileSystemEntity, Platform;
import 'package:path/path.dart' as path_lib;
/// Static helper class for determining platform's app data path.
///
/// Does not require [AppData] to work, can be standalone.
/// Paths for MacOS and Linux were choosen based on popular
/// StackOverflow answers. Submit a PR if you believe these are
/// wrong.
class Locator {
@shan-shaji
shan-shaji / work-with-multiple-github-accounts.md
Created October 12, 2022 16:12 — forked from rahularity/work-with-multiple-github-accounts.md
How To Work With Multiple Github Accounts on your PC

How To Work With Multiple Github Accounts on a single Machine

Let suppose I have two github accounts, https://github.com/rahul-office and https://github.com/rahul-personal. Now i want to setup my mac to easily talk to both the github accounts.

NOTE: This logic can be extended to more than two accounts also. :)

The setup can be done in 5 easy steps:

Steps:

  • Step 1 : Create SSH keys for all accounts
  • Step 2 : Add SSH keys to SSH Agent
@shan-shaji
shan-shaji / money.model.js
Created September 20, 2021 18:21 — forked from robert52/money.model.js
Approaches to create and combine models in mongoose. Document referencing, model composition and many more.
'use strict';
const DEF_CURRENCY = 'USD';
const DEF_SCALE_FACTOR = 100;
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ObjectId = Schema.ObjectId;
const MoneySchema = new Schema({
import 'dart:convert';
void main() {
String object = '{"name": "hello"}';
print(User.createInstance(jsonDecode(object)).name);
String name = null;
print(name);
}