Skip to content

Instantly share code, notes, and snippets.

View sarfarazansari's full-sized avatar

Sarfaraz Ansari sarfarazansari

View GitHub Profile
//assuming array look like this.
var arr = [
["Status", "Name", "Marks", "Position"],
["active", Sarfaraz, 10.0, "Front-end-dev"],
["active", John, 10.0, "Front-end-dev"],
["deactive", Raganar, 10.0, "UI designer"],
];
console.log (arrToObject(arr));
@sarfarazansari
sarfarazansari / SimpleGithubUser.factory.js
Last active February 14, 2017 05:15
Factory example for ECMA+Angular
export function SimpleGithubUser ($http) {
'ngInject';
var apiUrl = 'https://api.github.com/';
// instantiate our initial object
var SimpleGithubUser = function(username) {
this.username = username;
this.profile = this.getProfile();
};
@sarfarazansari
sarfarazansari / check 2d array is empty or undefined
Created February 22, 2017 04:47
check if 2 dimensional array is empty and undefined by using try catch
var arr1 = [
['A', 'B', 'C'],
['D', 'E', 'F']
];
var arr2 = [
['A', 'B', 'C'],
[]
];
export class HomeService {
constructor($log, $window, $rootScope, $http, $resource) {
'ngInject';
this.$log = $log;
this.$http = $http;
this.$window = $window;
this.$rootScope = $rootScope;
@sarfarazansari
sarfarazansari / check_elem_is_visible_in_viewport.js
Created June 17, 2017 08:55
Check for html element is visible in viewport by pure javascript (vanilla)
function isVisibleInViewport(id) {
var element = document.getElementById(id);
var rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
var options = {
height: 684, // sets the height in pixels of the window.
width: 585, // sets the width in pixels of the window.
toolbar: 0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
scrollbars: 0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
status: 0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
resizable: 0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
left: 0, // left position when the window appears.
top: 0, // top position when the window appears.
@sarfarazansari
sarfarazansari / nodejs_aws_s3_file_upload.js
Last active March 15, 2024 09:40
How to upload files to AWS S3 with NodeJS - AWS-SDK? With the help of this library you can upload any kind of file to s3. (NODEJS, AWS-SDK, S3)
/**
* we are going to upload file to s3 via node js by using
* aws-sdk - required
* busboy - required
* uuid - optional - for image renaming purpose
* with this library you can upload any kind of file to s3 via node js.
*/
const AWS = require('aws-sdk');
const UUID = require('uuid/v4');
@sarfarazansari
sarfarazansari / promise.js
Created August 21, 2018 05:44
using promise with angular httpclient
let url = `${YOUR_URL}`;
let promise = new Promise((resolve: any, reject) => {
this._httpClient.get(url).toPromise()
.then(
(res: any) => {
resolve(res);
},
err => {
reject(err);
@sarfarazansari
sarfarazansari / move-array-position.js
Created September 13, 2018 11:59
move array position by passing old and new positions.
public moveArrayPosition(arr: any[], oldPosition: number, newPosition: number) {
if (newPosition >= arr.length) {
let k = newPosition - arr.length + 1;
while (k--) {
arr.push(undefined);
}
}
arr.splice(newPosition, 0, arr.splice(oldPosition, 1)[0]);
return arr;
}
@sarfarazansari
sarfarazansari / notification.ts
Created March 7, 2019 03:27
show electron app notification according to OS
/**
* author: sarfaraz@walkover.in
* purpose: show native notifications accroding to os
*/
import { ipcMain, BrowserWindow } from 'electron';
import * as notifier from 'node-notifier';
import * as path from 'path';
import * as elog from 'electron-log';