Skip to content

Instantly share code, notes, and snippets.

View jaredcwhite's full-sized avatar
🌲

Jared White jaredcwhite

🌲
View GitHub Profile
@kristoferjoseph
kristoferjoseph / single-file-web-component.html
Last active November 22, 2023 01:17
Single file Web Component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Single File Web Component</title>
</head>
<body>
<template id=single-file>
<style>
h1 {
@petermueller
petermueller / README.md
Last active September 29, 2023 10:41
Phoenix + esbuild + yarn + postcss + tailwindcss + cpx2

Getting started

If you just want to copy-paste this it should "just work", but you'll need to get yarn set up. Follow the instructions at https://yarnpkg.com/getting-started/install OR just run:

  • npm install -g yarn
  • yarn set version berry
  • yarn install # this should make a .yarn/, yarn.lock, and .pnp.js

Mix Tasks

If you want to run these outside of the context of a running phoenix server, you can also run the mix tasks, mix assets.install and mix assets.compile. They are a copy paste of some the CLI bits but you could abstract them out to point to a config/cmds.exs or something if you wanted.

esbuild

@asgerb
asgerb / index.js
Created June 11, 2021 11:50
netlify-cache-bridgetown-media-transformation
module.exports = {
// Restore file/directory cached in previous builds.
// Does not do anything if:
// - the file/directory already exists locally
// - the file/directory has not been cached yet
async onPreBuild({ utils }) {
await utils.cache.restore("./.bmt-cache")
},
// Cache file/directory for future builds.
// Does not do anything if:
@KonnorRogers
KonnorRogers / imageable.rb
Last active February 19, 2021 23:27
Inline SVGs and Webp picture tags
# frozen_string_literal: true
# Useful methods for dealing with images
module Imageable
def inline_svg(filename, **options)
filepath = File.join(Rails.root, 'public', asset_pack_path("media/images/#{filename}.svg"))
Rails.cache.fetch(filepath) do
file = File.read(filepath)
doc = Nokogiri::HTML::DocumentFragment.parse file
@iscott
iscott / simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Last active March 15, 2024 03:23
Cheat Sheet: Simple Authentication in Rails 5 with has_secure_password

Cheat Sheet: Simple Authentication in Rails 6 with has_secure_password

The goal of this cheatsheet is to make it easy to add hand-rolled authentication to any rails app in a series of layers.

First the simplest/core layers, then optional layers depending on which features/functionality you want.

Specs
AUTHOR Ira Herman
LANGUAGE/STACK Ruby on Rails Version 4, 5, or 6
@narainsagar
narainsagar / nodejs - get filesize in readable format.md
Last active January 14, 2022 05:33
node.js - function to get file and convert the file size in humanly readable format.

node.js - get the filesize in human readable format.

This will take filePath as a function parameter and reads the file via fs module and get the file and converts it's size into more humanly readable format.

const fs = require('fs');
function getFileSize(filename) {
  const stats = fs.statSync(filename);
  //console.log('stats', stats);
 const {size} = stats;
anonymous
anonymous / contentblocks.rb
Created March 21, 2015 23:29
Gives you a mechanism in Jekyll to pass content up from pages into their parent layouts. It's kind of like having Rails' content_for available for Jekyll.
# Plugin: jekyll-contentblocks
# Author: Rusty Geldmacher
# Git: https://github.com/rustygeldmacher/jekyll-contentblocks
# Instructions: https://github.com/rustygeldmacher/jekyll-contentblocks#usage
module Jekyll
module ContentBlocks
VERSION = "0.0.3"
module Common
def get_content_block_name(tag_name, block_name)
block_name = (block_name || '').strip
@adambeynon
adambeynon / bindings.rb
Created May 7, 2014 15:58
Opal Bound attributes + DOM Compiler
module Vienna
class BaseBinding
def initialize(view, context, node, attr)
@view = view
@context = context
@node = node
@attr = attr
setup_binding
end
@schickling
schickling / Rakefile
Last active January 31, 2024 23:00
Activerecord without Rails
require "active_record"
namespace :db do
db_config = YAML::load(File.open('config/database.yml'))
db_config_admin = db_config.merge({'database' => 'postgres', 'schema_search_path' => 'public'})
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(db_config_admin)