Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Ivan Turkovic Thorsson

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

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
Thorsson / README.md
Created Nov 25, 2020 — forked from jesster2k10/README.md
JWT Auth + Refresh Tokens in Rails
View README.md

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
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)]
end
def marshal_load data
send :initialize, data[0]
instance_variable_set :@association_cache, data[1]
instance_variable_set :@new_record, data[2]
end
@Thorsson
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":')
end
puts %w(
platform
@Thorsson
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 https://code.google.com/p/v8/issues/detail?id=2291
const type = typeof value;
return type === 'function' || (!!value && type === 'object');
}
function ofPropertyChanges(obj, key) {
if (isObject(obj) === false) {
return Rx.Observable.return(undefined);
@Thorsson
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 "https://github.com/jwt/ruby-jwt" gem to your "Gemfile"
gem 'jwt'
@Thorsson
Thorsson / README.md
Created Oct 25, 2016 — forked from pbojinov/README.md
Two way iframe communication
View README.md

Two way iframe communication

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

Parent

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

iframe

@Thorsson
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
/*
Usage:
var jsoncheck = require('./wantsJSON') // path to file with this middleware function
app.use(jsoncheck)
app.get('/', function(req,res,next){
if (req.wantsJSON) {
// serve JSON
}
if (req.wantsHTML) {
@Thorsson
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