Skip to content

Instantly share code, notes, and snippets.

@bnhansn
bnhansn / vite-plugin-touch-file.ts
Created January 2, 2024 18:16
Vite Plugin Touch File
import fs from 'fs'
import path from 'node:path'
import process from 'node:process'
import micromatch from 'micromatch'
import type { Plugin } from 'vite'
export interface VitePluginTouchFileOptions {
touchFile: string
watchFiles: string | string[]
glob?: boolean
@bnhansn
bnhansn / readme.md
Last active August 8, 2023 05:53
Ubuntu Elixir Distillery Deployment

Rough outline of setting up a Ubuntu server for deploying an Elixir app with Distillery.

ssh into server

ssh root@ip.address

update packages

files:
"/etc/init/sidekiq.conf":
mode: "120400"
content: "/opt/elasticbeanstalk/support/conf/sidekiq.conf"
commands:
reload_initctl_for_sidekiq:
command: "initctl reload-configuration"
files:
"/opt/elasticbeanstalk/support/conf/sidekiq.conf":
mode: "000755"
content: |
description "Elastic Beanstalk Sidekiq Upstart Manager"
start on runlevel [2345]
stop on runlevel [06]
# explained above
respawn
respawn limit 3 30
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/03_mute_sidekiq.sh":
mode: "000755"
content: |
#!/bin/bash
. /opt/elasticbeanstalk/support/envvars
PIDFILE=/var/app/containerfiles/pids/sidekiq.pid
if [ -f ${PIDFILE} ]
then
kill -USR1 `cat ${PIDFILE}`
web: MIX_ENV=prod mix phoenix.server
transport :websocket, Phoenix.Transports.WebSocket, timeout: 45_000
@bnhansn
bnhansn / prod.exs
Last active November 21, 2016 02:02
# ...
config :sling, Sling.Endpoint,
http: [port: {:system, "PORT"}],
url: [scheme: "https", host: "nameless-reaches-32969.herokuapp.com", port: 443], # substitute your app's name
cache_static_manifest: "priv/static/manifest.json",
secret_key_base: System.get_env("SECRET_KEY_BASE"),
check_origin: ["http://sling-chat.s3-website-us-west-2.amazonaws.com"] # substitute you frontend's domain
# ...
// @flow
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { connectToChannel, leaveChannel, createMessage, loadOlderMessages } from '../../actions/room'; // add loadOlderMessages
import MessageList from '../../components/MessageList';
import MessageForm from '../../components/MessageForm';
import RoomNavbar from '../../components/RoomNavbar';
import RoomSidebar from '../../components/RoomSidebar';
type MessageType = {
defmodule Sling.MessageView do
use Sling.Web, :view
def render("index.json", %{messages: messages, pagination: pagination}) do
%{
data: render_many(messages, Sling.MessageView, "message.json"),
pagination: pagination
}
end