Skip to content

Instantly share code, notes, and snippets.

View mikker's full-sized avatar
👋

Mikkel Malmberg mikker

👋
View GitHub Profile
@mikker
mikker / something_system_spec.rb
Created September 9, 2019 06:55
Receive and expect Stripe webhook events in your Rails system tests
require 'system_helper'
RSpec.describe 'Something', type: :system do
it 'receives an event', :with_stripe_events do
make_request_at_stripe
wait_for_stripe_event { |e| e.type == 'charge.succeeded' }
expect(...)
end
end
@mikker
mikker / action_controller_media_type_hack.rb
Created August 5, 2019 07:11
Monkey patch action controller in Rails 6.0.0.rc2 to avoid deprecation warning
# Require this in config/application.rb after require "action_controller/railtie"
module ActionController
module Renderers
remove :json
remove :js
remove :xml
add :json do |json, options|
json = json.to_json(options) unless json.kind_of?(String)
@mikker
mikker / twitter.com.js
Created July 31, 2019 08:24
Automatically switch (back) to Latest Tweets timeline
function main() {
console.log("tick");
// Find the header signifying current timeline mode
const title = document.querySelector(
'[data-testid="primaryColumn"] h2[role="heading"]'
);
// If it isn't loaded yet, try again in 0.5 secs
if (!title) {
# frozen_string_literal: true
class VideoUrlParser
VideoMatch = Struct.new(:type, :video_id, :matches)
def initialize(url)
@url = url
@match = match_url
@type = @match.type
@video_id = @match.video_id
Metrics/BlockLength:
Exclude:
- "spec/**/*_spec.rb"
Rails/Delegate:
Enabled: false
Rails/HasAndBelongsToMany:
Enabled: false
Verifying my Blockstack ID is secured with the address 17Wp7UfqKqy6JsjRF5w2yHi2jaZBMQcZt8 https://explorer.blockstack.org/address/17Wp7UfqKqy6JsjRF5w2yHi2jaZBMQcZt8
/* globals fetch */
require('isomorphic-fetch')
const { parse } = require('url')
const { send } = require('micro')
module.exports = async (req, res) => {
const { query } = parse(req.url)
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Content-Type', 'application/json')
@mikker
mikker / Connected.js
Last active January 11, 2017 13:10
Higher Order Function for Redux with Next.js
import { Component } from 'react'
import { Provider, connect } from 'react-redux'
import { reducer, initStore } from './store'
export default function Connected (...args) {
return function (Comp) {
return class StoreComponent extends Component {
static getInitialProps ({ req }) {
const isServer = !!req
const store = initStore(reducer, undefined, isServer)
@mikker
mikker / let.rb
Last active September 6, 2016 10:34
require 'ostruct'
# Make little bundles of variables using Let {}
#
# example:
# things = Let {
# self.posts = Post.all
# self.comments = Comment.where(post: posts)
# }
#
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
/* ACTIONS */
export const ADD = 'something_clever/ADD'
export function add () {
return { type: ADD }
}