Skip to content

Instantly share code, notes, and snippets.

View sarfarazansari's full-sized avatar

Sarfaraz Ansari sarfarazansari

View GitHub Profile
@sarfarazansari
sarfarazansari / function.php
Last active February 14, 2022 04:25
add custom column in wp admin for custom post type
// Add the custom columns to the rezept post type:
add_filter( 'manage_rezept_posts_columns', 'set_custom_edit_rezept_columns' );
function set_custom_edit_rezept_columns($columns) {
unset($columns['date']);
return array_merge ( $columns, array (
'name' => __('Vor- & Nachname'),
'email' => __('E-mail Adresse'),
'group_of_people' => __('Personengruppe'),
'activation_date' => __('Erstellungsdatum'),
import {
Component,
ContentChild,
ElementRef,
EventEmitter,
Inject,
Optional,
Input,
NgModule,
NgZone,
// due to a classic closure problem
for (let i = 0; i < found.length; i++) {
setTimeout(() => {
found[i].time = + new Date();
// set values in db to see item in pinned list
}, i * 2000);
}
import { autoUpdater } from 'electron-updater';
import { dialog, webContents, app, ipcMain, BrowserWindow } from 'electron';
import { ProgressInfo } from 'builder-util-runtime';
import * as log from 'electron-log';
export default class AppUpdater {
constructor() {
log.transports.file.level = 'debug';
autoUpdater.logger = log;
if (process.platform === 'darwin' || process.platform === 'win32') {
autoUpdater.checkForUpdatesAndNotify();
@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';
@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 / 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 / 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');
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 / 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)
);
}