This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
given a non-empty array A consisting of N integers, returns the starting position of the slice with the minimal average. If there is more than one slice with a minimal average, you should return the smallest starting position of such a slice. | |
For example, given array A such that: | |
A[0] = 4 | |
A[1] = 2 | |
A[2] = 2 | |
A[3] = 5 | |
A[4] = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
given a non-empty array A consisting of N integers and integer X, returns the earliest time when the frog can jump to the other side of the river. | |
If the frog is never able to jump to the other side of the river, the function should return −1. | |
For example, given X = 5 and array A such that: | |
[1, 3, 1, 4, 2, 3, 5, 4] | |
the function should return 6, as explained above. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(N) { | |
const binString = N.toString(2); | |
const matches = binString.replace(/[0]+$/, '').match(/0+/g); | |
return (matches || []).reduce( (acc, cur) => Math.max(acc, cur.length), 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
"on": | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
name: release | |
runs-on: ubuntu-latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#my-input').addEventListener('keydown', restrictKeyboardInput); | |
$('#my-input').addEventListener('paste', restrictKeyboardInput); | |
function restrictKeyboardInput(event) { | |
if (event.type === 'keydown' && !event.key.match(/^[a-zA-Z0-9-_\ .]$/)) { | |
if (event.keyCode === 8 || event.keyCode === 46 || event.keyCode === 9) { | |
// Allow backspace, delete and Tab key | |
} else if (event.keyCode >= 37 && event.keyCode <= 40) { | |
// Allow left, right, up and down arrows | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('lazyLoading',[]) | |
.component('childAngularComponent', ChildAngularComponent) | |
.component('childChildAngularComponent', ChildChildAngularComponent); | |
var ChildAngularComponent = { | |
template: ` | |
<div> | |
<h2>I'm Child Angular Component</h2> | |
<p>form.value: {{$ctrl.form.value}}</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const konsole = { | |
LOG_LEVEL: 'log', | |
LOG_LEVELS: | |
{ all: 0, debug: 1, log: 2, info: 3, warn: 4, error: 5, none: 6 }, | |
debug: function() { konsole.write('debug', arguments) }, | |
info: function() { konsole.write('info', arguments) }, | |
log: function() { konsole.write('log', arguments) }, | |
warn: function() { konsole.write('warn', arguments) }, | |
error: function() { konsole.write('error', arguments) }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, ElementRef, HostListener, forwardRef, AfterViewInit } from '@angular/core'; | |
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | |
@Component({ | |
selector: '[text-editable]', | |
template: '<ng-content></ng-content>', | |
providers: [ { | |
provide: NG_VALUE_ACCESSOR, | |
useExisting: forwardRef(() => TextEditableComponent), multi: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fireDOMChange(el, options={attributes: false, childList: true, subtree: true}) { | |
const observer = new MutationObserver(list => el.dispatchEvent(new CustomEvent('dom-change', {detail: list}))); | |
observer.observe(el, options); | |
} | |
function waitForIdle(el, options) { | |
options = Object.assign({ | |
wait: 100, attributes: false, childList: true, subtree: true | |
}, options); | |
return new Promise(resolve => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
console.log(`************************************************************************* | |
* This script will | |
* 1. Clean up local branches after merge and deleted (git remote prune origin) | |
* 2. Ask you to delete remote your stale branches that are | |
* - more than 3 months old | |
* - and, created by you | |
* To delete all users' stale branches, add --all at the end | |
************************************************************************`); | |
const execSync = require('child_process').execSync; |