Skip to content

Instantly share code, notes, and snippets.

View mubasshir's full-sized avatar
🎯
Focusing

Mubasshir Pawle mubasshir

🎯
Focusing
View GitHub Profile
@mubasshir
mubasshir / 010_resource_files.js
Last active April 2, 2018 08:01 — forked from jimthedev/010_resource_files.js
Shell script to automatically copy icons and splash screens in Cordova 8.0 / Ionic Framework 3.20.0
#!/usr/bin/env node
// this file lives at hooks/after_prepare/010_resource_files.js
//just replace your Project name with Eiosys
var filestocopy = [
{
"resources/android/icon/drawable-hdpi-icon.png":
"platforms/android/res/mipmap-hdpi/icon.png"
},
@mubasshir
mubasshir / highlight.ts
Created April 4, 2018 10:02
Angular 2 Search Highlight Pipe. Make searched char bold
import { PipeTransform, Pipe } from '@angular/core';
@Pipe({ name: 'highlight' })
export class HighlightPipe implements PipeTransform {
transform(text: string, search): string {
if (search && text) {
let pattern = search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
pattern = pattern.split(' ').filter((t) => {
return t.length > 0;
}).join('|');
import * as path from 'path';
import * as imager from 'multer-imager';
import * as dotenv from 'dotenv';
import * as fs from 'fs';
const ENV = process.env.NODE_ENV;
if (!ENV) {
const envFilePath = path.resolve(process.cwd(), 'env', !ENV ? '.env' : `.env.${ENV}`);
const envConfig = dotenv.parse(fs.readFileSync(envFilePath));
@mubasshir
mubasshir / paginate.dart
Created February 27, 2020 12:23
Dart Array Pagination
void main() {
List arr = [];
for (int i = 0; i < 100; i++) {
arr.add(i.toString());
}
int page = 1;
var startIndex = -1, endIndex = -1;
while (arr.length > 0 && endIndex != (arr.length - 1)) {
startIndex = (page - 1) * 10;
@mubasshir
mubasshir / inr-comma-separator.js
Last active August 3, 2020 08:09
Indian Rupee (INR) - comma separator
function formatNumber(numberToFormat) {
// converting to string
numberToFormat = numberToFormat + '' || '';
// to make it works for integer and floating as well
var numberAndDecimal = numberToFormat.split('.');
// decimals points only
var decimals = numberAndDecimal[1] || null;
// add commas
numberAndDecimal = numberAndDecimal[0].replace(/(\d)(?=(\d\d)+\d$)/g, "$1,");
// join
@mubasshir
mubasshir / axios-to-s3.ts
Created June 22, 2022 06:20
Upload image from Axios to S3
export class uploadToS3 {
async downloadRemoteFile(url: string): Promise<any> {
return new Promise((resolve, reject) => {
// make request
// import axios
axios({
url: url,
method: 'GET',
responseType: 'arraybuffer',
decompress: false,
@mubasshir
mubasshir / zipper_array_of_objects.ts
Created June 24, 2022 15:58
Merge/Zip Array of Objects with alternating elements
const posts = [{ id: 1, title: 'Post 1' }, { id: 2, title: 'Post 2' }, { id: 3, title: 'Post 3' }, { id: 4, title: 'Post 4' }];
const polls = [{ id: 1, question: 'Poll 1' }, { id: 2, question: 'Poll 2' }];
// get minimum length of both arrays
const minLength = Math.min(posts.length, polls.length);
// create
let postsAndPolls:any = [];
// loop through the array and fill it with the posts and polls
for (let i = 0; i < minLength; i++) {
// push ith post and ith poll to the array
postsAndPolls.push(posts[i], polls[i]);