Skip to content

Instantly share code, notes, and snippets.

View gopalkohli's full-sized avatar
☠️
I may be slow to respond.

Gopal Kohli gopalkohli

☠️
I may be slow to respond.
  • Novateur Inc
  • Bangalore
View GitHub Profile
@gopalkohli
gopalkohli / hexOrRGBToColor.dart
Created June 24, 2024 05:42 — forked from whiplashoo/hexOrRGBToColor.dart
Convert a hex, rgba, or rgb color string to Color object in Dart
import 'dart:ui';
import 'package:flutter/material.dart';
// Converts a hex, rgb, or rgba color string to Color object. Works with opacity values as well.
// e.g.:
// "#000" -> Color(0xff000000)
// "#cc3333" -> Color(0xffcc3333)
// "#cc3333dd" -> Color(0xddcc3333)
// "rgb(204, 44, 81)" -> Color(0xffcc2c51)
// "rgba(204, 44, 81, 0.20)" -> Color(0x33cc2c51)
@gopalkohli
gopalkohli / curl.php
Created February 16, 2024 05:26 — forked from surferxo3/curl.php
Script to demonstrate how to extract Header and Body from the Curl response in PHP.
<?php
/*#############################
* Developer: Mohammad Sharaf Ali
* Designation: Web Developer
* Version: 1.0
*/#############################
// SETTINGS
ini_set('max_execution_time', 0);
@gopalkohli
gopalkohli / jwt_decode.php
Created January 25, 2024 08:24 — forked from ahgood/jwt_decode.php
Get payload data from JWT token.
<?php
/**
* JSON Web Token implementation
*
* Minimum implementation used by Realtime auth, based on this spec:
* http://self-issued.info/docs/draft-jones-json-web-token-01.html.
*
* @author Neuman Vong <neuman@twilio.com>
*/
class JWT
@gopalkohli
gopalkohli / UINavigationController+extensions.swift
Created September 23, 2023 19:00 — forked from matsuda/UINavigationController+extensions.swift
Completion handler for UINavigationController push or pop
/// https://stackoverflow.com/a/33767837
/// https://iganin.hatenablog.com/entry/2019/07/27/172911
extension UINavigationController {
public func pushViewController(
_ viewController: UIViewController,
animated: Bool,
completion: @escaping () -> Void) {
pushViewController(viewController, animated: animated)
guard animated, let coordinator = transitionCoordinator else {
DispatchQueue.main.async { completion() }
@gopalkohli
gopalkohli / 1-standard.js
Created May 9, 2023 07:34 — forked from vladfr/1-standard.js
Use async/await and for..of in Cloud Firestore
// In a Firestore standard example, we quickly create a 'xmas tree' of nested stuff
// We use Promises directly: get().then(callback) and use snapshot.forEach() to iterate
let campaignsRef = db.collection('campaigns');
let activeCampaigns = campaignsRef.where('active', '==', true).select().get()
.then(snapshot => {
snapshot.forEach(campaign => {
console.log(campaign.id);
let allTasks = campaignsRef.doc(campaign.id).collection('tasks').get().then(
snapshot => {
snapshot.forEach(task => {
@gopalkohli
gopalkohli / data.dart
Created March 20, 2023 15:17 — forked from kirshiyin89/data.dart
Call to Datamuse api to retreive the data.
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert' as convert;
class BackendService {
static Future<List<Map<String, String>>> getSuggestions(String query) async {
if (query.isEmpty && query.length < 3) {
print('Query needs to be at least 3 chars');
return Future.value([]);
}
@gopalkohli
gopalkohli / material_app.dart
Created March 20, 2023 15:17 — forked from kirshiyin89/material_app.dart
MaterialApp class.
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'data.dart';
class MyMaterialApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Datamuse Autocomplete Demo',
home: MyHomePage(),
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
Future<void> main() async {
runApp(const MyApp('Printing Demo'));
}
@gopalkohli
gopalkohli / helpers.php
Created May 13, 2021 14:33 — forked from dacastro4/helpers.php
Laravel 5 Helper Methods (PHP 7+)
<?php
/**
* Created by PhpStorm.
* User: danielcastro
* Date: 2/2/17
* Time: 2:06 PM
*
* Place under app/paht/to/file folder and add
* "files" : [
* "app/paht/to/file/helpers.php"
@gopalkohli
gopalkohli / responsive-request-desktop-site.js
Created March 2, 2021 08:04 — forked from dtipson/responsive-request-desktop-site.js
How to make responsive sites better respect the "Request a desktop site" feature on modern mobile browsers.
/*
Enable the "Request Desktop Site" functions on mobile chrome (android and iOS) allow users to see desktop layouts on responsive sites. Note that this is distinct from "opt out of mobile!" buttons built into your site: this is meant to work with the browser's native opt-in/opt-out functionality.
Since these functions work, in part, by simply spoofing the user agent to pretend to be desktop browsers, all we have to do is just remember that the browser once claimed to be android earlier in the same session and then alter the viewport tag in response to its fib.
Here's an example viewport tag <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> that we'd be setting to scaleable-yes,max scale=2. That's just an example of something that works on the site I was building: you should customize the "desktop" viewport content setting to whatever works for your site's needs. If you wanted, you could stick this code in the head just after the primary viewport tag so that the br