Skip to content

Instantly share code, notes, and snippets.

@chrise86
chrise86 / application.rb
Created May 26, 2012 08:53
A rails log silencer for specific calls / actions
# config/application.rb
require File.dirname(__FILE__) + '/../lib/custom_logger.rb'
module MyApp
class Application < Rails::Application
# Middlewares
config.middleware.swap Rails::Rack::Logger, CustomLogger, :silenced => ["/noisy/action.json"]
end
end
@chrise86
chrise86 / active_link_to.rb
Created March 28, 2023 09:03 — forked from dcyoung-dev/active_link_to.rb
An `active_link_to` helper that adds the `.active` class and sets `aria-current="page"`
@chrise86
chrise86 / generators-service-USAGE
Created June 22, 2022 08:30 — forked from RobinDaugherty/generators-service-USAGE
Rails generator for services and lib objects
Description:
Stubs a new Service object in the `lib` folder and a spec for it.
Providing a list of argument names will set up the initializer to accept them
and create private accessors for each of them.
To create a service within a module, specify the service name as a
path like 'parent_module/service_name' or 'ParentModule::ServiceName'.
Example:
@chrise86
chrise86 / Confetti.tsx
Created April 9, 2020 07:16 — forked from ShopifyEng/Confetti.tsx
Building Arrive's Confetti in React Native with Reanimated - Confetti Final
import React, {useMemo} from 'react'
import Animated from 'react-native-reanimated'
import {View, Dimensions, StyleSheet} from 'react-native'
import FastImage from 'react-native-fast-image'
import ConfettiImage from 'assets/images/confetti.png'
const NUM_CONFETTI = 100
const COLORS = ['#00e4b2', '#09aec5', '#107ed5']
const CONFETTI_SIZE = 16
/* Fixing back button in normal density */
:root:not([uidensity=compact]) #back-button {
padding-top: 0 !important;
padding-bottom: 0 !important;
}
:root:not([uidensity=compact]) #back-button > .toolbarbutton-icon {
background-color: unset !important;
border: none !important;
}
// transform cropper dataURI output to a Blob which Dropzone accepts
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type: 'image/jpeg' });
}
@chrise86
chrise86 / DropZone.jsx
Created August 20, 2016 17:35 — forked from pizzarob/01_DropZone.jsx
HTML5 Drag and Drop React Component
import React, {PropTypes} from 'react';
import classNames from 'classnames';
class BatchDropZone extends React.Component {
static propTypes = {
// function that recieves an array of files
receiveFiles: PropTypes.func.isRequired,
@chrise86
chrise86 / call_template.rb
Last active March 2, 2018 11:30 — forked from juggy/call_template.rb
Render a complete page in rails 5 without controller
# create the template
template = PageOfflineTemplate.new
template.quote = quote
template.pages = quote.build_pages
# Here I render a template with layout to a string then a PDF
pdf = PDFKit.new template.render_to_string(:template=>"quotes/review.html.haml")
@chrise86
chrise86 / rails_api_token_auth_with_tiddle.md
Created January 18, 2018 11:01 — forked from brunofacca/rails_api_token_auth_with_tiddle.md
Rails API token authentication with Tiddle gem in apps with web views

This gist attempts to explain how to implement token authentication in Rails, using Devise and Tiddle. Tiddle was designed to provide token auth for API-only Rails apps. However, the following instructions will enable you to use it in Rails apps which have both APIs and web views.

##Why Tiddle?

Devise is the obvious choice for authentication on Rails. However, token authentication was

@chrise86
chrise86 / application_helper.rb
Last active November 18, 2017 09:49 — forked from dnagir/application_helper.rb
Render a different variant in rails
module ApplicationHelper
def with_variant(new_variant, &block)
old_variants = lookup_context.variants
begin
lookup_context.variants = [new_variant]
return block.call
ensure
lookup_context.variants = old_variants
end
end