Skip to content

Instantly share code, notes, and snippets.

View Lawondyss's full-sized avatar

Ladislav Vondráček Lawondyss

  • freelancer
  • Liberec
View GitHub Profile
function qs(selector: string, parent: ParentNode = document): Element | null {
return parent.querySelector(selector)
}
function qsa(selector: string, parent: ParentNode = document): Element[] {
return [...parent.querySelectorAll(selector)]
}
function createElement(type: string, options: Record<string, string | object> & Partial<{ class: string, dataset: object, text: string }> = {}): HTMLElement {
const elm = document.createElement(type)
@Lawondyss
Lawondyss / oneline_snippets.js
Created March 16, 2023 07:59
JavaScript one-line snippets
const randomNumber = (min, max) => Math.random() * (max - min) + min;
const isNil = (val) => val === null || val === undefined;
const removeDuplicates = (arr) => [...new Set(arr)];
const isDateString = (val) => !isNaN(Date.parse(val));
const shuffle = (arr) => arr.sort(() => Math.random() - 0.5);
@Lawondyss
Lawondyss / AngularJS Confirmation
Created February 6, 2014 18:30
Uses CSS framework SemanticUI.
angular.module('Confirmation', [])
.directive 'ngConfirmClick', ($parse) ->
restrict: 'A'
link: (scope, element, attrs) ->
popId = Math.floor Math.random() * 10000000000
attrs.popId = popId
message = attrs.message ? 'Do you really want to delete?'
okLabel = attrs.okLabel ? 'Yes'
cancelLabel = attrs.cancelLabel ? 'No'
@Lawondyss
Lawondyss / AngularJS FlashMessage
Last active January 2, 2016 21:49
Uses CSS framework SemanticUI.
myApp = angular.module 'myApp', []
myApp.service 'FlashMessage', ($rootScope) ->
Flash = () ->
$rootScope.flashes = []
$rootScope.$on '$routeChangeSuccess', () ->
$rootScope.$broadcast 'FlashMessage:reset', $rootScope.flashes = []
return