Skip to content

Instantly share code, notes, and snippets.

Avatar
☀️

Sunny Ripert sunny

☀️
View GitHub Profile
View cults_graphql.php
<?php
$query = <<<'JSON'
{
creations(limit: 1) {
name
url
creator {
nick
}
View cults_graphql.py
# Example GraphQL call using https://github.com/prisma/python-graphql-client
from sgqlc.endpoint.http import HTTPEndpoint
import base64
query = '''
{
creations(limit: 1) {
name
url
@sunny
sunny / add_frozen_string_literal_comment.rb
Last active Nov 23, 2022 — forked from ta1kt0me/add_frozen_string_literal_comment.rb
Add frozen string literal comment into generated files in Rails 7
View add_frozen_string_literal_comment.rb
# frozen_string_literal: true
# Via https://gist.github.com/ta1kt0me/6a7058d16621785d4f7038bde6cd3b98
module RailsGeneratorFrozenStringLiteralPrepend
RUBY_EXTENSIONS = %w[.rb .rake].freeze
def render
return super unless RUBY_EXTENSIONS.include?(File.extname(destination))
"# frozen_string_literal: true\n\n#{super}"
View html-fetch.js
const htmlFetch = async (url, { headers, body, ...options } = {}) => {
const token = document.querySelector('meta[name="csrf-token"]').content;
options = {
headers: new Headers({
Accept: "text/html",
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest",
"X-CSRF-Token": token,
...headers,
View blog_article_seeds.rb
# frozen_string_literal: true
class Blog::ArticlePlanter < Planter
def check(slug_en:)
Blog::Article.where(slug_en: slug_en).any?
end
def create(params)
FactoryBot.create(:blog_article, params)
end
@sunny
sunny / select_definitions_controller.js
Created Sep 8, 2021
Stimulus controller to show/hide elements
View select_definitions_controller.js
import { Controller } from "stimulus";
// Show/hide elements based on the value of a select element.
//
// Example:
// <div data-controller="select-definitions">
// <select
// data-select-definitions-target="select"
// data-action="change->select-definitions#change"
// >
@sunny
sunny / pagy_standalone_app.ru
Last active Aug 18, 2021
Pagy Standalone to test trim + custom URLs
View pagy_standalone_app.ru
# frozen_string_literal: true
# Self-contained, standalone Sinatra app usable to play with pagy
# and/or easily reproduce any pagy issue.
# Copy this file in your own machine and
# ensure rack is installed (or `gem install rack`)
# USAGE:
# rackup -o 0.0.0.0 -p 8080 pagy_standalone_app.ru
View keybase.md

Keybase proof

I hereby claim:

  • I am sunny on github.
  • I am sunfox42 (https://keybase.io/sunfox42) on keybase.
  • I have a public key ASDTUFctmlgvsQC0k66qtvmcGhmcO_CtzpmW0D-cdx-xSAo

To claim this, I am signing this object:

@sunny
sunny / i18n.rb
Created Oct 5, 2020
Show i18n keys when locale is "translate"
View i18n.rb
# config/initializers/i18n.rb
I18n::Backend::Simple.include(I18n::Backend::TranslateLocale)
@sunny
sunny / application_controller.rb
Last active Oct 6, 2020
Rails helper so that "?_locale_keys=1" in URL shows locale keys
View application_controller.rb
class ApplicationController < ActionController::Base
include I18nHelper
end