Skip to content

Instantly share code, notes, and snippets.

View chloerei's full-sized avatar

Rei chloerei

View GitHub Profile
require "importmap/npm"
require "importmap/packager"
namespace :importmap do
desc "Download"
task :download do
npm = Importmap::Npm.new
packager = Importmap::Packager.new
packages = npm.packages_with_versions.map { |item| item.join("@") }
imports = packager.import(packages)
@chloerei
chloerei / graphql_client.rb
Last active October 22, 2023 12:55
A simple graphql client without define schema.
require "net/http"
require "json"
# client = Graphql::Client.new("http://localhost:3000/graphql", { "Authorization" => "Bearer token..." })
# response = client.execute("query { ... }", { name: "value" })
class Graphql::Client
def initialize(endpoint, headers = {})
@endpoint = endpoint
@headers = headers
end
@chloerei
chloerei / _button.html.erb
Last active September 12, 2023 07:24
a turbo stream update example
<%
voted = Current.user && post.votes.exists?(user: Current.user)
%>
<div id="<%= dom_id(post, :vote) %>", class="inline-block align-middle">
<% if voted %>
<%= form_with url: site_post_vote_path(post), method: :delete do |form| %>
<%= render "components/button", type: :submit, style: :outlined, label: post.votes_count, icon: :arrow_upward, active: true %>
<% end %>
<% else %>
version: '3.4'
services:
web:
build: .
command: bin/rails server -b 0.0.0.0
volumes:
- .:/rails
ports:
- 3000:3000
测试
test
@chloerei
chloerei / .bash_profile
Created March 21, 2015 08:09
Config gem user install
export GEM_HOME="$(ruby -rubygems -e 'puts Gem.user_dir')"
PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@chloerei
chloerei / create_user.sh
Created March 5, 2014 07:07
Create a deploy user with githu keys when setup vps
#!/bin/bash
USER=deploy
KEYS_PATH=https://github.com/chloerei.keys
useradd -s /bin/bash -m deploy
passwd $USER
adduser $USER sudo
mkdir /home/$USER/.ssh
wget $KEYS_PATH -O /home/$USER/.ssh/authorized_keys
@chloerei
chloerei / jekyll_image_fetcher.rb
Last active December 24, 2015 05:19
Fetch images and replace link in markdown posts.
# = Usage
# Download to your jekyll site directory, and run it
# `ruby jekyll_image_fetcher.rb`
Dir['_posts/*.md'].each do |path|
content = File.open(path).read
basename = File.basename path, '.md'
content.gsub!(/!\[\]\((.+)\)/) do |m|
url = $1