Skip to content

Instantly share code, notes, and snippets.

View alekseyg's full-sized avatar

Aleksey Gladysh alekseyg

View GitHub Profile
const isAutoplaySupported = function (callback) {
var timeout;
var waitTime = 200;
var retries = 5;
var currentTry = 0;
var elem = document.createElement('video');
var elemStyle = elem.style;
function testAutoplay(arg) {
currentTry++;
@alekseyg
alekseyg / stripe.js
Created March 15, 2017 22:03
What Stripe.applePay.checkAvailability actually does
Stripe.applePay.checkAvailability = function (callback) {
if (location.protocol === 'https:') {
var canMakePayments = window.ApplePaySession && ApplePaySession.canMakePayments()
if (/^pk_test_/.test(Stripe.key || Stripe.publishableKey)) {
callback(canMakePayments)
} else if (canMakePayments) {
var merchantId = "merchant." + window.location.hostname + ".stripe"
ApplePaySession.canMakePaymentsWithActiveCard(merchantId).then(callback)
} else {
@alekseyg
alekseyg / tooltip.js
Last active April 20, 2017 02:13
Make tooltips work on iOS by using touch events and ignoring mouse events
;(function ($) {
var wasTapped = function wasTapped (element) {
var touchStart = element.data('lastTouchStart')
var touchEnd = element.data('lastTouchEnd')
return (
touchStart && touchEnd &&
touchEnd.timeStamp - touchStart.timeStamp <= 500 && // duration
Math.abs(touchEnd.pageX - touchStart.pageX) <= 10 && // deltaX
Math.abs(touchEnd.pageY - touchStart.pageY) <= 10 // deltaY
)
<!DOCTYPE html>
<html>
<head>
<title>LinkToBug</title>
<link data-turbolinks-track="true" href="/assets/application.css?body=1" media="all" rel="stylesheet" />
<link data-turbolinks-track="true" href="/assets/bug.css?body=1" media="all" rel="stylesheet" />
<script data-turbolinks-track="true" src="/assets/jquery.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/jquery_ujs.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/turbolinks.js?body=1"></script>
<script data-turbolinks-track="true" src="/assets/bug.js?body=1"></script>
form.awesome {
// Defaults for custom inputs
.custom {
display: inline-block;
width: 16px;
height: 16px;
position: relative;
top: 2px;
border: solid 1px $custom-form-border-color;
require 'rubygems'
require 'active_record'
# Print out what version we're running
puts "Active Record #{ActiveRecord::VERSION::STRING}"
# Connect to an in-memory sqlite3 database
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
@alekseyg
alekseyg / counter_cache_bug.rb
Created April 17, 2013 00:54
This demonstrates a bug in the Rails implicit counter_cache. When creating a record with nested records via a nested form, it does not increment the {child}s_count, but when deleting via a nested form, it decrements the field.
require 'rubygems'
require 'active_record'
# Print out what version we're running
puts "Active Record #{ActiveRecord::VERSION::STRING}"
# Connect to an in-memory sqlite3 database
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'