Skip to content

Instantly share code, notes, and snippets.

@dima-f1
dima-f1 / asyncLoop.js
Created July 31, 2018 12:00
Comparison of two techniques of looping promises inside async function
function resolveAfter2Seconds(x, isFail) {
return new Promise((resolve, reject) => {
setTimeout(() => {
isFail ? reject() : resolve(x);
}, 2000);
});
}
function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
@dima-f1
dima-f1 / Adobe-ask-experts.md
Created November 3, 2015 09:38 — forked from dbox/Adobe-ask-experts.md
Answer for adobe ask the experts

Q: What is your favorite Css 'trick'?

Responsive images in CSS are pretty easy: just set the width: 100% and height: auto and you're good to go. Things get a little unpredictable, though, when dealing with background images. Since putting a height on the element causes lots of responsive headaches, one workaround is to have the container scale by its aspect ratio. This can be achieved by setting a few attributes to the element's :after tag:

.my-element {
  overflow: hidden;
  position: relative;
}
.my-element:after {
 content: "";
@dima-f1
dima-f1 / demo.html
Created July 3, 2015 12:03
Angular custom select box
<stylish-select options="countries_list" ev="profileEditRender.country" ng-model="tabsWizard.filled.profile.country_code">
<option value="default">Country</option>
</stylish-select>
<stylish-select name="account-gender" class="" ng-disabled="!user_owns_this" ng-model="accountInfo.gender" ev="profileEditRender.gender">
<option value="U">Gender</option>
<option value="M">Male</option>
<option value="F">Female</option>
</stylish-select>
@dima-f1
dima-f1 / outside-click-directive.js
Created July 2, 2015 13:15
AngularJS outside click directive
function() {
return {
restrict: 'A',
scope: {
outsideClickException: '@',
outsideClickCallback: '&'
},
link : function (scope, element, attr) {
$(document).on('click', function (event) {
var isClickedElementChildOfPopup = element[0].contains(event.target) || $(event.target).hasClass(scope.outsideClickException);
@dima-f1
dima-f1 / demo.js
Created June 29, 2015 16:57
Detecting CSS Animation and Transition End with JavaScript
var item = document.querySelector( '.item' );
item.classList.add( 'disappear' );
item.onCSSAnimationEnd( function()
{
item.parentNode.removeChild( item );
});
@dima-f1
dima-f1 / index.jade
Last active August 29, 2015 14:23
css multiple backgrounds
div.bacground-container
@dima-f1
dima-f1 / once.js
Created June 14, 2015 13:18
Javascript function that will run only once
function once(fn, context) {
var result;
return function() {
if(fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result;
@dima-f1
dima-f1 / poll.js
Created June 14, 2015 13:13
Javascript poll function
function poll(fn, callback, errback, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
(function p() {
// If the condition is met, we're done!
if(fn()) {
callback();
}
// If the condition isn't met but the timeout hasn't elapsed, go again
@dima-f1
dima-f1 / directives.js
Last active August 29, 2015 14:22 — forked from dpogorzelski/directives.js
Twitter share directive
directives.directive('twitter', [
function() {
return {
link: function(scope, element, attr) {
setTimeout(function() {
twttr.widgets.createShareButton(
attr.url,
element[0],
function(el) {}, {
count: 'none',
@dima-f1
dima-f1 / Custom fonts load event
Last active August 29, 2015 14:21
Отслеживаем событие загрузки кастомного шрифта с помощью FontFaceObserver
<style>
@import url(http://fonts.googleapis.com/css?family=НАЗВАНИЕ_ШРИФТА&subset=cyrillic,latin);
/* шрифт по умолчанию, до тех пор пока не подгружен новый шрифт */
body {font-family: sans-serif;}
/* новый шрифт */
.fontOneLoad body {
font-family: 'НАЗВАНИЕ_ШРИФТА', cursive;
}
</style>