Skip to content

Instantly share code, notes, and snippets.

View spaquet's full-sized avatar
🎯
Focusing

spaquet spaquet

🎯
Focusing
View GitHub Profile
@spaquet
spaquet / index.html.erb
Last active January 18, 2022 19:28
Rails Popper Stimulus Index file
<section class="bg-gray-100 h-full w-full">
<div class="container mx-auto px-2 md:px-4 py-4">
<div class="flex justify-center items-center h-full md:h-screen">
<div class="flex flex-col p-5 border border-gray-500 bg-white shadow-xl rounded-xl w-96 h-96 items-center justify-center">
<h2>Button with popper</h2>
<div data-controller="popper">
<button id="button" data-popper-target="element" data-action="mouseenter->popper#show mouseleave->popper#hide" class="bg-blue-500 text-blue-100 px-3 py-2 rounded-xl">
Over me!
<div id="tooltip" role="tooltip" data-popper-target="tooltip">
My tooltip
@spaquet
spaquet / popper.css
Last active January 18, 2022 19:12
Rails Popper Stimulus Stylesheet
#tooltip {
background: #333;
color: white;
font-weight: bold;
padding: 4px 8px;
font-size: 13px;
border-radius: 4px;
display: none;
}
#arrow,
@spaquet
spaquet / popper_controller.js
Created January 18, 2022 02:59
Rails Popper Stimulus Controller
import { Controller } from "@hotwired/stimulus";
import { createPopper } from "@popperjs/core";
// Connects to data-controller="popper"
export default class extends Controller {
static targets = ["element", "tooltip"];
static values = {
placement: { type: String, default: "top" },
offset: { type: Array, default: [0, 8] },
};
@spaquet
spaquet / Pascal.swift
Last active December 26, 2021 19:56
Swift Pascal Triangle Recursive Solution (not optimized)
import Foundation
func solve(_ numRows: Int, _ result: [[Int]]?) -> [[Int]] {
guard numRows > 0 else {
return []
}
var tmp = [[Int]]()
var tmpIndex = 0
@spaquet
spaquet / AppleSignInButton.swift
Created April 5, 2020 16:12
Custom SwiftUI Apple Sign In button using the AppleSignIn Singleton
Button(action: {
AppleSignIn.sharedInstance.appleSignIn()
}) {
HStack (alignment: .center, spacing: 38) {
Image("apple")
.resizable()
.scaledToFill()
.frame(width: 18, height: 24, alignment: .center)
Text("Sign up With Apple")
.fontWeight(.semibold)
@spaquet
spaquet / AppleSignIn.swift
Last active April 5, 2020 16:07
AppleSignIn Singleton to use in SwiftUI
//
// AppleSignIn.swift
//
import Foundation
import FirebaseAuth
import AuthenticationServices
import CryptoKit
final class AppleSignIn: NSObject {
@spaquet
spaquet / Controller
Last active July 16, 2017 15:56
Basic Rails User Controller & Model (API)
class UsersController < ApplicationController
before_action :set_user, only: [:show, :update, :destroy]
# GET /users
def index
@users = User.all
render json: @users
end