Skip to content

Instantly share code, notes, and snippets.

View simonfranzen's full-sized avatar
🦉

Simon Franzen simonfranzen

🦉
View GitHub Profile
@simonfranzen
simonfranzen / graphql_generator.rb
Last active June 26, 2019 09:04
RubyOnRails GraphQL Type Generator
# lib/generators/rails/graphql/graphql_generator.rb
# run with "rails generate graphql my_model"
class Rails::GraphqlGenerator < Rails::Generators::NamedBase
def create_graphql_type_file
attributes = ""
begin
klass = Object.const_get(class_name)
obj = klass.new
@simonfranzen
simonfranzen / email_interceptor.rb
Last active June 6, 2019 14:03
RubyOnRails E-Mail Whitelisting for Mailer
class EmailInterceptor
# just an example to allow only *@zauberware.com emails
REGEX_WHITELIST = /.*@zauberware\.com/
def self.delivering_email(message)
if !in_whitelist?(message.to.first)
message.perform_deliveries = false
end
end
@simonfranzen
simonfranzen / background_task_job.rb
Created January 16, 2019 11:19
A base class for background tasks, rubyonrails
class BackgroundTaskJob < Struct.new(:background_task_id, :background_task_type)
def enqueue(job)
check_and_update_status
job.delayed_reference_id = background_task_id
job.delayed_reference_type = background_task_type
job.save!
end
@simonfranzen
simonfranzen / routes.rb
Created December 2, 2018 18:56
Redirect all routes in RubyOnRails
Rails.application.routes.draw do
constraints(:host => /^(?!old-domain\.com)/i) do
match "/(*path)" => redirect {
|params, req| "https://new-domain.com/#{params[:path]}"
}, via: [:get, :post]
end
end
@simonfranzen
simonfranzen / gif.bash
Last active October 19, 2018 17:48
GIF from video // Run with $ sh gif.bash -i=InputFile.mov -o=OutputFile
#!/bin/bash
# Run with $ sh gif.bash -i=InputFile.mov -o=OutputFile
for i in "$@"
do
case $i in
-i=*|--input=*)
INPUT_FILE="${i#*=}"
;;
@simonfranzen
simonfranzen / Sample.jsx
Last active October 18, 2018 12:28
styled-component boilerplate
import styled, { css } from 'styled-components'
import { media } from 'styled-bootstrap-grid'
import { padding } from 'polished'
const Sample = styled.div`
/* 1. Default mobile first styles */
${ padding('10px', '14px', '10px', '8px') }
color: black;
@simonfranzen
simonfranzen / Button.tsx
Last active May 6, 2021 10:47
FramerX Styled Component Example Button
import * as React from "react"
import { PropertyControls, ControlType } from "framer"
import styled, { css } from "styled-components"
const StyledButton = styled.button`
padding: 20px;
border-radius: 10px;
border: 0;
font-size: 2em;
@simonfranzen
simonfranzen / cookie_notice.html
Last active May 26, 2018 00:16
Plain HTML Cookie Acceptor
@simonfranzen
simonfranzen / jquery.await-response.js
Created April 5, 2018 09:37
Small jQuery helper to disable buttons while AJAX request is loading.
// Small jQuery helper to disable buttons while AJAX request is loading.
// Init the helper for all buttons on page with $('.js-await-response').awaitResponse()
// If a button with your class was klicked, the button itself and all others with that class will be disabled until the response came back
(function ( $ ) {
$.fn.awaitResponse = function( options ) {
var self = this;
// listening to starting AJAX events
@simonfranzen
simonfranzen / theme.less
Last active February 5, 2018 22:04
Get rid of HumHubs border radius
/**
* Define or overwrite your theme selectors within this file.
**/
//
// HumHub CSS override
// remove border-radius (HumHub v. 1.2.4)
//
.badge,
.btn,