Skip to content

Instantly share code, notes, and snippets.

View kwent's full-sized avatar
👻
Happy Halloween 🎃

Quentin Rousseau kwent

👻
Happy Halloween 🎃
View GitHub Profile
@justalever
justalever / validate_array_datatype.rb
Created January 3, 2020 03:08
Validate an array data type in Ruby on Rails using a custom validator - PostGresQL allows arrays as a DB type.
# Define the validator
# app/validators/array_validator.rb
class ArrayValidator < ActiveModel::EachValidator
def validate_each(record, attribute, values)
Array(values).each do |value|
options.each do |key, args|
validator_options = { attributes: attribute }
validator_options.merge!(args) if args.is_a?(Hash)
import UploadAdapter from './upload_adapter';
function CustomUploadAdapterPlugin( editor ) {
editor.plugins.get( 'FileRepository' ).createUploadAdapter = ( loader ) => {
// Configure the URL to the upload script in your back-end here!
return new UploadAdapter( loader, editor );
};
}
import { Controller } from "stimulus"
require 'apple_id'
# NOTE: in debugging mode, you can see all HTTPS request & response in the log.
# AppleID.debug!
pem = <<-PEM
-----BEGIN PRIVATE KEY-----
:
:
-----END PRIVATE KEY-----
@slightfoot
slightfoot / always_scrollbar.dart
Created March 4, 2019 18:20
Always Visible Scrollbar for Flutter - 4th March 2019
import 'package:flutter/gestures.dart' show DragStartBehavior;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.indigo,
@danott
danott / pre-commit
Last active July 23, 2024 21:51
A git hook that automatically formats JavaScript and Ruby code on commit
#!/bin/sh
# ./.git/hooks/pre-commit
.git/hooks/pre-commit-format-javascript
.git/hooks/pre-commit-format-ruby
@JasonTrue
JasonTrue / searchkick_and_elasticsearch_guidance.md
Last active March 11, 2025 03:37
Searchkick and Elastic Search guidance

Resources:

https://github.com/ankane/searchkick

Indexing

By default, simply adding the call 'searchkick' to a model will do an unclever indexing of all fields (but not has_many or belongs_to attributes).

In practice, you'll need to customize what gets indexed. This is done by defining a method on your model called search_data

def search_data

@dangerouse
dangerouse / CloudSpongeWidget.jsx
Last active September 21, 2021 19:29
CloudSponge - Example React Component
import React from 'react'
// Simple React Component that manages adding the cloudsponge object to the page
// and initializing it with the options that were passed through.
// props:
// * cloudspongeKey (required): your widget key from your CloudSponge account https://app.cloudsponge.com/app
// * options (optional): any javascript options you wish to pass to configure the cloudpsonge object
//
// For example, you can use the component like so:
// import CloudSpongeWidget from './CloudSpongeWidget'
# config/initializers/activestorage.rb
Rails.application.config.to_prepare do
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
ActiveStorage::Attached::Macros.module_eval do
def has_one_attached(name, dependent: :purge_later, acl: :private)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||= ActiveStorage::Attached::One.new("#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"}, acl: "#{acl}")
end
@Miouyouyou
Miouyouyou / zebra_print_header.txt
Created April 3, 2018 13:37
Generate EPL code allowing you to print a QRCode with a Zebra 2746e (European and American versions)
; !! IF YOU'RE OPENING THIS FILE ON UNIX/LINUX SYSTEMS, KEEP THE CRLF !!
; !! USE unix2dos IF YOUR EDITOR IS TOO DUMB TO KEEP THEM !!
; This is a comment (Assembly-like comments)
; Set the form length (Distance between each print ??)
Q0001,0
; The label width in dots
q831
; Set the double buffer mode (For what purpose, I have no idea)
rN
; Print speed : [2-6] = [level_selected*25] mm/s -> (2 == 2*25 mm/s) -> 50 mm/s
@xsot
xsot / instructions.md
Last active March 3, 2024 13:42
sed maze solver

Usage

sed -E -f solver.sed input where input is a file containing the maze.

For best results, resize your terminal to match the height of the maze. To disable animations, delete the lines containing p.

Maze format

The solver assumes the following:

  • The maze only contains the characters # \nSE
  • Every line has the same number of characters
  • There is only one start (S) and end (E)