Skip to content

Instantly share code, notes, and snippets.

@snowyu
snowyu / ts-quasar-cli.md
Created September 8, 2018 13:19
Add the typescript supports to quasar framework

Note: This guide applies to the project created by quasar-cli.

First install typescript and ts-loaderpackages in your project.

npm i -D typescript ts-loader

Then modified the quasar.conf.js file in your project:

@ind1go
ind1go / default.html
Created July 9, 2018 19:37
html-pipeline plugin and ERB tags to take absolute URLs to relative URLs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="<%= name %> GraphQL documentation">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title><%= title || name %></title>
<%
def relative_filename_path(opts)
@bgentry
bgentry / base_connection.rb
Last active May 10, 2019 05:23
graphql-ruby class-based Relay connections + edges, with totalCount field on all connections. Adapted from http://rmosolgo.github.io/blog/2018/04/09/updating-github-to-graphql-1-dot-8-0/
# frozen_string_literal: true
module Types
class BaseConnection < BaseObject
# For some reason these are needed, they call through to the underlying connection wrapper.
extend Forwardable
def_delegators :@object, :cursor_from_node, :parent
# When this class is extended, add the default connection behaviors.
# This adds a new `graphql_name` and description, and searches
@igrep
igrep / parser-strscan.rb
Last active June 16, 2023 21:14
Arithmetic expression parser with StringScanner in Ruby, inspired by parser combinators.
require 'strscan'
class Parser
def initialize string
@scanner = StringScanner.new string
end
def self.eval string
self.new(string).expr
@nicolas-brousse
nicolas-brousse / active_admin.js
Last active May 14, 2021 18:45
Formtastic PostgreSQL Array input (inspered from https://gist.github.com/franks921/44509c65da3bea99bc49)
$('form .input.array').each(function() {
var $wrapper = $('.array-inputs', this);
var $insertArea = $(".array-input button[data-action=add]").closest(".array-input");
$(".array-input button[data-action=add]", $(this)).click(function(e) {
$('.array-input:first-child', $wrapper).clone(true).insertBefore($insertArea).find('input').val('').focus();
});
$('.array-input button[data-action=remove]', $wrapper).click(function() {
if ($('.array-input', $wrapper).length > 2) {
$(this).parent('.array-input').remove();
}
@wingrunr21
wingrunr21 / environment.js
Created October 2, 2017 19:43
Simple webpacker server side rendering
const webpack = require('webpack')
const { environment } = require('@rails/webpacker')
// Don't use commons chunk for server_side_render chunk
const entries = environment.toWebpackConfig().entry
const commonsChunkEligible = Object.keys(entries).filter(name => name !== 'server_side_render')
environment.plugins.set('CommonsChunkVendor', new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module, count) => {
@AleksandrKudashkin
AleksandrKudashkin / sanitize.rb
Created September 6, 2017 20:06
Loofah custom scrubber for youtube and vimeo iframes
class CustomScrubber < Loofah::Scrubber
ALLOWED_IFRAME_ATTRS = %w[allowfullscreen frameborder height src width].freeze
ALLOWED_VIDEO_REGEX = %r{\A(?:https?:)?//(?:www\.)?youtube|vimeo(?:-nocookie)?\.com/}
def scrub(node)
if node.name == 'iframe' && node['src'] =~ ALLOWED_VIDEO_REGEX
node.attribute_nodes.each { |a| a.remove unless ALLOWED_IFRAME_ATTRS.include?(a.name) }
return CONTINUE
end
return CONTINUE if html5lib_sanitize(node) == CONTINUE
@jcalz
jcalz / builderPattern.ts
Created July 25, 2017 14:44
Builder Pattern example code
type IBuilder<T> = {
[k in keyof T]: (arg: T[k]) => IBuilder<T>
} & { build(): T }
function proxyBuilder<T>(): IBuilder<T> {
var built: any = {};
var builder = new Proxy({}, {
get: function(target, prop, receiver) {
if (prop === 'build') return () => built;
return (x: any): any => {
@theorygeek
theorygeek / association_loader.rb
Last active October 31, 2023 07:15
Preloading Associations with graphql-batch
# frozen_string_literal: true
class AssociationLoader < GraphQL::Batch::Loader
attr_reader :klass, :association
def initialize(klass, association)
raise ArgumentError, "association to load must be a symbol (got #{association.inspect})" unless association.is_a?(Symbol)
raise ArgumentError, "cannot load associations for class #{klass.name}" unless klass < ActiveRecord::Base
raise TypeError, "association #{association} does not exist on #{klass.name}" unless klass.reflect_on_association(association)
@klass = klass
@gskema
gskema / color-gradient.js
Last active March 2, 2024 22:14
Generate gradient color from 2 or 3 colors using JavaScript. Example: https://jsfiddle.net/e18g5f3L/
/**
* You may use this function with both 2 or 3 interval colors for your gradient.
* For example, you want to have a gradient between Bootstrap's danger-warning-success colors.
*/
function colorGradient(fadeFraction, rgbColor1, rgbColor2, rgbColor3) {
var color1 = rgbColor1;
var color2 = rgbColor2;
var fade = fadeFraction;
// Do we have 3 colors for the gradient? Need to adjust the params.