Skip to content

Instantly share code, notes, and snippets.

View paulcsmith's full-sized avatar

Paul Smith paulcsmith

View GitHub Profile
@KonnorRogers
KonnorRogers / port_in_use.rb
Last active August 17, 2020 17:51
Check if a port is being used.
require "socket"
def detect_port!
hostname = Snowpacker.config.hostname || "localhost"
port = Snowpacker.config.port || 4035
server = TCPServer.new(hostname, port)
server.close
rescue Errno::EADDRINUSE
puts "#{port} is currently being used"
exit!
@stephendolan
stephendolan / lucky_spec_action.yml
Last active April 27, 2020 21:48
GitHub Action - Lucky Setup and Spec
name: Lucky Build and Spec CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
def mount(component, *args, **named)
component.new(*args, **named).render do |*yield_args|
yield *yield_args
end
end
class Component
def initialize(@name : String)
end
@gilesvangruisen
gilesvangruisen / ci.yml
Created April 5, 2020 15:58
Ruby/Rails GitHub Actions CI
name: rspec
on:
pull_request:
branches:
- "master"
push:
branches:
- "master"
@manveru
manveru / bytea.cr
Last active December 2, 2019 23:31
Additional types for Avram
record Bytea, bytes : Bytes
struct Bytea
def self.adapter
Lucky
end
def blank?
@bytes.size == 0
end
@reinink
reinink / DateInput.vue
Created August 27, 2019 11:51
Pikaday Vue Component
<template>
<div>
<label v-if="label" class="form-label" :for="`date-input-${_uid}`">{{ label }}:</label>
<input v-bind="$attrs" class="form-input" :id="`date-input-${_uid}`" :class="{ error: error }" type="text" ref="input" :value="value" @change="change" @keyup="change">
<div v-if="error" class="form-error">{{ error }}</div>
</div>
</template>
<script>
import pikaday from 'pikaday'
@watzon
watzon / not_pwned_validation.cr
Created June 14, 2019 18:27
Lucky valdator to make sure a password isn't in the Have I Been Pwned database
require "http/client"
require "openssl"
module NotPwnedValidation
def validate_not_in_hibp
password.value.try do |value|
hash = get_sha1_hash(value).upcase
first_five = hash[0...5]
response = HTTP::Client.get("https://api.pwnedpasswords.com/range/" + first_five)
hashes = response.body.split("\r\n")
@watzon
watzon / app.js
Last active June 14, 2019 18:23
Toggle password field with Lucky and stimulus
import { Application } from 'stimulus'
import PasswordController from './controllers/password_controller'
const application = Application.start()
application.register("password", PasswordController)
@calebporzio
calebporzio / pure_html_css_modal.css
Last active February 28, 2022 18:15
The CSS for the pure HTML/CSS modal I tweeted about.
details summary {
cursor: pointer;
outline: none !important;
display: inline-block;
padding: 8px 12px;
padding-top: 10px;
border-radius: 4px;
overflow: hidden;
background: #F09825;
color: white;
@paulcsmith
paulcsmith / lucky.cr
Last active April 19, 2019 19:05
Lucky search form
class Candidates::Searches::Show < BrowserAction
get "/candidates/search" do
CandidateSearchForm.new(params).submit do |form, candidates|
render Candidates::IndexPage, search_form: form, candidates: candidates
end
end
end
class CandidateSearchForm < Avram::VirtualForm
virtual query : String