Skip to content

Instantly share code, notes, and snippets.

View SackeyDavid's full-sized avatar

David Sackey SackeyDavid

View GitHub Profile
@SackeyDavid
SackeyDavid / Angular Browser AutoFill Detector Directive
Created January 25, 2024 13:54
This Angular directive provides a simple way to detect native autofill on an input field and emit an event when the autofill status changes. It uses a debounce mechanism and a promise to asynchronously check for autofill, allowing for a more responsive user experience.
import { Directive, ElementRef, Output, EventEmitter, OnInit } from "@angular/core";
@Directive({
selector: "[nativeAutofill]",
})
export class NativeAutofillDetector implements OnInit {
private elRef: HTMLInputElement;
@Output()
public nativeAutofill: EventEmitter<boolean> = new EventEmitter<boolean>();
@SackeyDavid
SackeyDavid / addElementsHTML.ts
Created October 17, 2021 21:24
Add elements dynamically to HTML DOM
// parent div
var checkboxDiv = document.querySelector('#must-haves');
if(checkboxDiv.childElementCount > 0) {
let checkboxDivContents = checkboxDiv.innerHTML;
let str = checkboxDivContents + '<table><tbody><tr><td><ion-checkbox class="checkbox" checked="true" style="width: 50vw;--border-radius: .35rem;--background: #EEF0F2;--border-color: #EEF0F2;" color="dark"></ion-checkbox></td><td style="position: relative;top: -.19rem;"><span style="margin-left: calc(-50vw + 2.15rem)">'+ instructionData.instruction + '</span></td></tr></tbody></table>';
checkboxDiv.innerHTML = str;
} else {
checkboxDiv.innerHTML = this.addCheckbox(instructionData.instruction);
@SackeyDavid
SackeyDavid / app.component.html
Created October 3, 2021 00:55
Angular app component html default file
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<!-- * * * * * * * * * * * The content below * * * * * * * * * * * -->
<!-- * * * * * * * * * * is only a placeholder * * * * * * * * * * -->
<!-- * * * * * * * * * * and can be replaced. * * * * * * * * * * * -->
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<!-- * * * * * * * * * Delete the template below * * * * * * * * * * -->
<!-- * * * * * * * to get started with your project! * * * * * * * * -->
<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -->
<style>
@SackeyDavid
SackeyDavid / extra-long-factorial.js
Created September 29, 2021 22:14
Turing Coding Challenge Extra Long Factorial
function extraLongFactorials(n) {
// check constraints
if(!(n >= 1 && n <= 100 )) return 0;
let fact = 1;
for (let i = 2; i <= n; i++){
if(Number.isSafeInteger(fact*i)){
@SackeyDavid
SackeyDavid / gist:d24315dd844d51b3e70af062fdcf5941
Created September 19, 2021 03:04
Turing Coding Challenge Practise Test - Problem 2
// console.log("Hello, World!");
var countElements = function(arr) {
var result = 0;
// output = 0;
// count elements
for (var i = 0; i < arr.length; i++) {
if(arr.includes(arr[i] + 1)) {
result+= 1
}
@SackeyDavid
SackeyDavid / gist:11701048859f47b7b98fbcc69631a033
Created September 19, 2021 01:51
Turing Coding Challenge Practise Test
// console.log("Hello, World!");
var calPoints = function(ops) {
result = null;
output = [];
checks = true;
// check constraints
// check if operations length constraints is met
if(!(ops.length >= 1 || ops.length <= 1000))
import React, { Component } from 'react'
import { StyleSheet, View, Animated } from 'react-native'
import { theme } from '../constants';
export default class Block extends Component {
handleMargins() {
const { margin } = this.props;
if (typeof margin === 'number') {
return {