Skip to content

Instantly share code, notes, and snippets.

@mhluska
mhluska / fix-fastmail-1password.js
Created September 19, 2022 00:21
Fix for Fastmail Masked Email + 1Password Firefox extension prefill
for (const elem of document.querySelectorAll('[type="email"],[placeholder*=email i],[aria-label*=email i]')) {
const prevName = elem.name;
const clone = elem.cloneNode();
clone.name = 'email';
elem.replaceWith(clone);
setTimeout(() => { clone.replaceWith(elem) }, 5000);
}
@mhluska
mhluska / gmail-unsubscribe.js
Created May 23, 2021 22:49
Tampermonkey Script - Gmail Unsubscribe
// ==UserScript==
// @name Gmail Unsubscribe
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Unsubscribe by pressing \
// @author Maros Hluska
// @homepage https://mhluska.com
// @match https://mail.google.com/*
// @icon https://www.google.com/s2/favicons?domain=tampermonkey.net
// @grant none
@mhluska
mhluska / fixtures.js
Last active March 13, 2019 22:43
No circular reference
const util = require('util')
norm_widget_1 = {
'foo': 1,
'bar': 'baz',
'_jv': {
'type': 'widget',
'id': '1',
'relationships': {
'widgets': {
@mhluska
mhluska / document.js
Last active September 7, 2018 12:09
Simulate document.querySelector() in Ember FastBoot
import Service, { inject as service } from '@ember/service';
import { getOwner } from '@ember/application';
import { computed } from '@ember/object';
export default Service.extend({
fastboot: service(),
init() {
this._elemCache = {};
this._super(...arguments);
@mhluska
mhluska / current-user.js
Last active September 3, 2018 10:51
Ember-simple-auth Current User Service
import Service, { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
export default Service.extend({
store: service(),
session: service(),
auth: alias('session.data.authenticated'),
@mhluska
mhluska / user.rb
Last active September 13, 2018 12:21
Rails Many-to-many relationship generating incorrect SQL
class User < ApplicationRecord
has_many :order_items_bought,
-> { joins(:order).where.not(orders: { state: :expired }).order(created_at: :desc) },
foreign_key: :buyer_id,
class_name: :OrderItem
has_many :videos_bought,
-> { joins(:orders).select('DISTINCT ON (videos.id) videos.*').reorder('videos.id DESC') },
through: :order_items_bought,
source: :item,
@mhluska
mhluska / sanity.js
Created June 18, 2018 08:56
Sanity-ember-service
import Service, { inject as service } from '@ember/service';
export default Service.extend({
ajax: service(),
store: service(),
fastboot: service(),
client: null,
init() {
@mhluska
mhluska / visual_regression.rb
Last active June 10, 2018 12:52
Quick and dirty visual regression testing with Rails + Capybara + Selenium
# spec/rails_helper.rb
if ENV['SAVE_SCREENSHOTS']
module CapybaraElementExtensions
INTERACTION_METHODS = %i[set select_option unselect_option click
right_click double_click send_keys hover trigger drag_to execute_script
evaluate_script evaluate_async_script]
INTERACTION_METHODS.each do |method|
define_method method do |*args, &block|
@mhluska
mhluska / controllers.application.js
Last active February 16, 2018 08:53 — forked from wuarmin/controllers.application.js
async_model_loading
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Videos'
});
@mhluska
mhluska / basic-video.js
Created January 26, 2018 03:01
Ember Performance Issue
import Component from '@ember/component';
import { computed } from '@ember/object';
import {
noop,
} from 'lodash';
export default Component.extend({
tagName: 'video',
classNameBindings: ['isPlaying'],