Skip to content

Instantly share code, notes, and snippets.

View peterfication's full-sized avatar

Peter Morgenstern peterfication

View GitHub Profile
jobs:
build:
docker:
...
- image: docker.elastic.co/elasticsearch/elasticsearch:6.4.2
@peterfication
peterfication / welcome_mail.js
Last active May 21, 2018 17:47
welcome_mail.js
import { generateFetchLocale } from 'lib/utils'
import * as React from 'react'
import Button from 'templates/html/snippets/Button'
import Closing from 'templates/html/snippets/Closing'
import Footer from 'templates/html/snippets/Footer'
import FullWidthBorder from 'templates/html/snippets/FullWidthBorder'
import Greeting from 'templates/html/snippets/Greeting'
import Header from 'templates/html/snippets/Header'
import Layout from 'templates/html/snippets/Layout'
// This file has to be required before rails-ujs
// To use it change `data-confirm` of your links to `data-confirm-swal`
(function() {
const handleConfirm = function(element) {
if (!allowAction(this)) {
Rails.stopEverything(element)
}
}
const allowAction = element => {
document.addEventListener('rails:attachBindings', element => {
Rails.delegate(document, 'a[data-confirm-swal]', 'click', handleConfirm)
})
const handleConfirm = link => {
// Do your thing
}
Rails.delegate(document, 'a[data-confirm-swal]', 'click', handleConfirm)
@peterfication
peterfication / rails_sweetalert_confirm_webpacker.js
Last active November 28, 2017 15:36
Rails SweetAlert confirm Webpacker
import Rails from 'rails-ujs';
const handleConfirm = () => {
// Do your thing
}
// Add event listener before the other Rails event listeners like the one
// for `method: :delete`
Rails.delegate(document, 'a[data-confirm-swal]', 'click', handleConfirm)
@peterfication
peterfication / sweetalert_rails_confirm_new_wrong.js
Last active November 30, 2017 06:49
First try SweetAlert Rails confirm new
// Override the default confirm dialog of Rails
Rails.handleConfirm = link => {
if (link.data('confirm') === undefined){
return true
}
showSweetAlertConfirmationDialog(link)
return false
}
@peterfication
peterfication / sweetalert_rails_confirm_old.js
Last active November 30, 2017 06:48
Rails SweetAlert confirm old
// Override the default confirm dialog of Rails
$.rails.handleConfirm = link => {
if (link.data('confirm') === undefined){
return true
}
showSweetAlertConfirmationDialog(link)
return false
}
// Analyze asana task export in JS console
// Format of a task title has to be "[estimated amount of time] title (Actual time used for the task)"
// It prints out the average deviation of the estimated time
// Open the export JSON in Chrome and run this script in the browser console
if (typeof(x) === 'undefined') {
const x = JSON.parse($('pre').innerHTML)
}
var differences = []
@peterfication
peterfication / vimgolf.js
Created April 19, 2017 08:22
Get all challenges of vimgolf.com as a list that can be copy and pasted into a spreadsheet.
// Copy and paste this script into the Javascript console at https://www.vimgolf.com
// and you get a tab delimited list of the entries that can be copied and pasted
// into a spreadsheet.
var resultString = [];
$('#content .grid_7 div h5').each(function(i, e) {
var $link = $(e).find('a');
var url = 'https://www.vimgolf.com' + $link.attr('href');
var urlParts = url.split('/');
var challengeID = urlParts[urlParts.length - 1];