Skip to content

Instantly share code, notes, and snippets.

View nmanikiran's full-sized avatar
🎯
Focusing

Mani Kiran Nalabolu nmanikiran

🎯
Focusing
View GitHub Profile
#!/bin/bash
STARTFOLDER="./"
MARKER="converted"
echo -n "Finding candidate files .."
FILELIST=$(find "$STARTFOLDER" -type f -name '*.mp4')
echo ".. "$(echo -e "$FILELIST" | wc -l)" found"
while read FILEPATH; do
@nmanikiran
nmanikiran / css-variable.js
Created May 16, 2020 17:34
Update CSS variables with javascript
var root = document.querySelector(':root');
var rootStyles = getComputedStyle(root);
var red = rootStyles.getPropertyValue('--red');
console.log('red: ', red);
root.style.setProperty('--red', 'green')
@nmanikiran
nmanikiran / getCursorPosition.js
Created March 11, 2020 07:32
getCursorPosition from contenteditable
getCursorPosition(editableDiv) {
editableDiv = editableDiv || this.element;
let caretOffset = 0;
if (window.getSelection) {
const range = window.getSelection().getRangeAt(0);
const preCaretRange = range.cloneRange();
preCaretRange.selectNodeContents(editableDiv);
preCaretRange.setEnd(range.endContainer, range.endOffset);
caretOffset = preCaretRange.toString().length;
@nmanikiran
nmanikiran / range_selection_save_restore.js
Created March 10, 2020 08:56 — forked from timdown/range_selection_save_restore.js
Range and selection marker-element-based save and restore
/**
* This is ported from Rangy's selection save and restore module and has no dependencies.
* Copyright 2019, Tim Down
* Licensed under the MIT license.
*
* Documentation: https://github.com/timdown/rangy/wiki/Selection-Save-Restore-Module
* Use "rangeSelectionSaveRestore" instead of "rangy"
*/
var rangeSelectionSaveRestore = (function() {
var markerTextChar = "\ufeff";
@nmanikiran
nmanikiran / console.js
Created December 23, 2019 11:59 — forked from Harshmakadia/console.js
Mastering JS console like a Pro
// time and time end
console.time("This");
let total = 0;
for (let j = 0; j < 10000; j++) {
total += j
}
console.log("Result", total);
console.timeEnd("This");
// Memory
// Some elements will cause a horizontal scroll bar to appear, due to the width of those elements
[].forEach.call($$("*"), function(a) {
a.style.outline =
"1px solid #" + (~~(Math.random() * (1 << 24))).toString(16);
});
// https://gist.github.com/addyosmani/fd3999ea7fce242756b1
@nmanikiran
nmanikiran / get-watchers.js
Created August 14, 2018 11:44 — forked from kentcdodds/get-watchers.js
Get Watchers of element and its children
function getWatchers(root) {
root = angular.element(root || document.documentElement);
var watcherCount = 0;
function getElemWatchers(element) {
var isolateWatchers = getWatchersFromScope(element.data().$isolateScope);
var scopeWatchers = getWatchersFromScope(element.data().$scope);
var watchers = scopeWatchers.concat(isolateWatchers);
angular.forEach(element.children(), function (childElement) {
watchers = watchers.concat(getElemWatchers(angular.element(childElement)));
async function loadFonts(fontName) {
let fontName = fontName || 'myfont';
const font = new FontFace(fontName, `url(${fontName}.woff)`);
await font.load();
document.fonts.add(font);
document.body.classList.add('fonts-loaded');
}
@nmanikiran
nmanikiran / angular-google-places-autocomplete-directive.ts
Created July 30, 2018 06:26
Google places autocomplete in angular
import { Directive, ElementRef, OnInit, Output, EventEmitter } from '@angular/core';
declare var google:any;
@Directive({
selector: '[google-place]'
})
export class GooglePlacesDirective implements OnInit {
@Output() onSelect: EventEmitter<any> = new EventEmitter();
private element: HTMLInputElement;
@nmanikiran
nmanikiran / Clean-Code.md
Created July 11, 2018 03:08
10 Tips For Clean Code

#1: You're responsible for code quality.

#2: Use meaningful names.

#3: Write code that expresses intent.

#4: Code should speak for itself. Less comments = less maintenance.

#5: Leave the code better than you found it.