Skip to content

Instantly share code, notes, and snippets.


Ivan Turkovic Thorsson

View GitHub Profile
Thorsson / a_rails_rspec_checklist\
Created Feb 13, 2021 — forked from BideoWego/a_rails_rspec_checklist\
Rails Spec setup checklist, helper and support files
View a_rails_rspec_checklist\

Rails RSpec Checklist

  • Ensure turbolinks is disabled for good measure

    • comment out gem
    • remove from javascript asset pipeline
    • remove from application layout
  • Add the following gems to Gemfile in a development, test group

    • hirb
Thorsson /
Created Nov 25, 2020 — forked from jesster2k10/
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

Thorsson / active_record_marshalable.rb
Created Apr 2, 2019 — forked from keichan34/active_record_marshalable.rb
Get Marshal.dump and Marshal.load to load cached association objects ( Whatever.includes(:example_models) ), as well.
View active_record_marshalable.rb
module ActiveRecordMarshalable
def marshal_dump
[attributes, self.association_cache, instance_variable_get(:@new_record)]
def marshal_load data
send :initialize, data[0]
instance_variable_set :@association_cache, data[1]
instance_variable_set :@new_record, data[2]
Thorsson / redux-orm-normalization.js
Created Feb 2, 2019 — forked from markerikson/redux-orm-normalization.js
Redux-ORM nested data normalization
View redux-orm-normalization.js
import {fk, many, Model} from 'redux-orm';
class Book extends Model {
static get fields() {
authors: many('Author', 'books'),
publisher: fk('Publisher', 'books'),
static parse(data) {
View rds_ri_prices_parser.rb
#!/usr/bin/env ruby
require 'json'
def parse(uri)
JSON.parse `curl -s #{uri}`.gsub(/\/\*(?:(?!\*\/).)*\*\//m, '').strip.gsub(/^callback\(/, '').gsub(/\);/, '').gsub(/([a-zA-Z]+[0-9]*):/, '"\1":')
puts %w(
Thorsson / ofPropertyPathChanges.js
Created Feb 1, 2017 — forked from jayphelps/ofPropertyPathChanges.js
RxJS observable of property value changes, given an object and property path
View ofPropertyPathChanges.js
function isObject(value) {
// Avoid an old bug in Chrome 19-20
// See
const type = typeof value;
return type === 'function' || (!!value && type === 'object');
function ofPropertyChanges(obj, key) {
if (isObject(obj) === false) {
return Rx.Observable.return(undefined);
Thorsson / Gemfile
Created Jan 17, 2017 — forked from goncalvesjoao/Gemfile
Changes you need to make in order to make Devise use JWT Header Authentication
View Gemfile
# Add the "" gem to your "Gemfile"
gem 'jwt'
Thorsson /
Created Oct 25, 2016 — forked from pbojinov/
Two way iframe communication

Two way iframe communication

The main difference between the two pages is the method of sending messages. Recieving messages is the same in both.


Send messages to iframe using iframeEl.contentWindow.postMessage Recieve messages using window.addEventListener('message')


Thorsson / wantsJSON.js
Created Sep 13, 2016 — forked from leereamsnyder/wantsJSON.js
Detect if a request in Express is for HTML or JSON
View wantsJSON.js
var jsoncheck = require('./wantsJSON') // path to file with this middleware function
app.get('/', function(req,res,next){
if (req.wantsJSON) {
// serve JSON
if (req.wantsHTML) {
Thorsson / Dockerfile
Created Aug 9, 2016 — forked from yefim/Dockerfile
Build a Docker image, push it to AWS EC2 Container Registry, then deploy it to AWS Elastic Beanstalk
View Dockerfile
# Example Dockerfile
FROM hello-world