Skip to content

Instantly share code, notes, and snippets.

@jaulz
jaulz / CursorPaginateDirective.php
Created March 28, 2023 17:33
CursorPaginateDirective
<?php
namespace App\GraphQL\Directives;
use Error;
use GraphQL\Language\AST\FieldDefinitionNode;
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
use GraphQL\Language\AST\NonNullTypeNode;
use GraphQL\Language\AST\ObjectTypeDefinitionNode;
use GraphQL\Language\Parser;
@sindresorhus
sindresorhus / esm-package.md
Last active May 20, 2024 14:52
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@micimize
micimize / react-native-issues.md
Last active March 24, 2019 20:26
My myriad problems experienced with react-native (I last worked with RN Sep 10th, 2018)

preface

This is a slightly cleaned-up version of the venting I did while pulling my hair out over react-native issues. The state of using react-native might be getting better with the community restructuring and core-rewrite. So take these dated notes with a grain of salt.

summary

After months of struggling to port libraries and develop applications using react-native, I have to recommend trading the comfort and breadth of the react and javascript ecosystems for Flutter and dart if you're developing a mobile app.

react-native is buggy and slow (or at least very hard to make fast). Perhaps it can be blamed on the size of the community, but the project is managed in an almost adversarial style. Almost all issues are ignored until the bot closes them for being "stale". They get locked too, just to make sure the community can't communicate work

@ibrahima
ibrahima / CodeBlock.jsx
Last active December 3, 2020 10:23
Syntax highlighting for react-markdown
import React from 'react';
import PropTypes from 'prop-types';
import SyntaxHighlighter from 'react-syntax-highlighter';
export default class CodeBlock extends React.PureComponent {
static propTypes = {
value: PropTypes.string.isRequired,
language: PropTypes.string,
}
@JulienSansot
JulienSansot / app.json
Created June 16, 2017 16:22
heroku postdeploy script to copy PG database
{
"scripts": {
"postdeploy": "pg_dump -Fc $DATABASE_URL_TO_COPY | pg_restore --clean --no-owner -n public -d $DATABASE_URL && bundle exec rails db:migrate"
}
}
@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
@rmosolgo
rmosolgo / Gemfile
Last active March 27, 2023 08:38
GraphQL Ruby Subscriptions
source 'https://rubygems.org'
gem "graphql", github: "rmosolgo/graphql-ruby", branch: "subscriptions"
gem "sinatra"
gem "thin"
@solnic
solnic / rom-sql-ar-like-polymorphic-associations.rb
Last active May 14, 2021 05:33
[rom-sql] AR-like polymorphic associations (PLEASE DON'T USE IT UNLESS YOU HAVE A LEGACY SCHEMA)
require 'rom-repository'
require 'rom-sql'
require 'logger'
config = ROM::Configuration.new(:sql, 'sqlite::memory')
config.gateways[:default].connection.create_table(:songs) do
primary_key :id
column :title, String
end
#!/usr/bin/env ruby
require 'bundler/inline'
require 'json'
gemfile(:install) do
gem 'rom', '>= 2.0', github: 'rom-rb/rom', branch: 'master'
gem 'rom-http', github: 'rom-http-rb/rom-http', branch: 'master'
gem 'faraday'
end