Skip to content

Instantly share code, notes, and snippets.

View joelmoss's full-sized avatar

Joel Moss joelmoss

View GitHub Profile
@obazoud
obazoud / oneshot.rb
Last active August 29, 2015 14:04
Chef: How to remove a recipe dynamically ?
ruby_block 'remove_dynamically_oneshot' do
block { node.run_list.remove('recipe[mycookbook::oneshot]') }
end
@marten
marten / deploy.rb
Created November 13, 2014 10:26
Capistrano Flowdock integration
set :format, :capture
# rest of your deploy.rb goes here
after 'deploy:started', 'notify:flowdock:started' do
$flowdock_deploy_thread = Deployer::Flowdock::Deployment.new(application: fetch(:application),
environment: fetch(:rails_env) || fetch(:rack_env),
repo_name: fetch(:repo_url).gsub(/\[email protected]:(.*).git/, "\\1"),
@salmanasiddiqui
salmanasiddiqui / notifications_controller.rb
Last active March 20, 2024 18:58
Right way to use Rails SSE for live notification
class NotificationsController < ApplicationController
def notify_me
# Rails reserve a db connection from connection pool for each request, lets put it back into connection pool.
ActiveRecord::Base.clear_active_connections!
# required header
response.headers['Content-Type'] = 'text/event-stream'
sse = ActionController::Live::SSE.new(response.stream)
#!/usr/bin/env node
/**
* Git COMMIT-MSG hook for validating commit message
* See https://docs.google.com/document/d/1rk04jEuGfk9kYzfqCuOlPTSJw3hEDZJTBN5E5f1SALo/edit
*
* Installation:
* >> cd <repo>
* >> ln -s ../../validate-commit-msg.js .git/hooks/commit-msg
*/

Faster Rails tests

Feedback loop speed in one of the biggest contributing factors to overall development time. The faster you get results, the faster you can move on to other things. A fast enough test suite is therefore critical to teams' success, and is worth investing some time at the beginning to save in the long run.

Below is a list of techniques for speeding up a Rails test suite. It is not comprehensive, but should definitely provide some quick wins. This list of techniques assumes you're using minitest, but most everything should translate over to rspec by simply replacing test/test_helper.rb with spec/spec_helper.rb.

@mwidmann
mwidmann / add_local_trusted_ca_for_valid_https.md
Last active July 2, 2024 03:58
Generating trusted SSL keys for development

Generating SSL keys for development

Installation

Thanks to minica it is very easy to create trusted SSL certificates that have a very long expiration date.

In order to get started you have to have the go tools installed and set up correctly in your environment.

Setup

Proposal: Importable Constructable Stylesheets

We're getting Constructable Stylesheets. This seems like an intuitive value to obtain when importing CSS from JavaScript, since it's the DOM's representation of a Stylesheet:

import stylesheet from './style.css';
console.log(stylesheet);  // CSSStyleSheet

No such system is in place to allow this to work (see [whatwg/loader]), however frontend build tooling has congregated around this approach as a mechanism for bringing CSS assets into the JavaScript module graph. There are many benefits to be obtained from moving CSS into this graph, however the most important is that imported CSS can be attributed to the consuming JS Module. This allows it to be bundled, optimized, and potentially dead-code-eliminated leveraging static analysis performed on the surrounding module graph.

@nickmarden
nickmarden / full_stack_rails_developer_skills_test.md
Last active July 24, 2023 13:16
Full-Stack Rails Developer Skills Test

PLEASE NOTE: Do not publicly post your answers on this Gist, please forward them to your recruiting contact instead ;-)

1. Voting

Each voter can vote in zero or more referenda. Each referendum has one or more questions, and each question is a yes/no vote. Write the simplest normalized schema to describe this in generic SQL statements or as an entity-relationship diagram. Point out where the indexes would be if you want to quickly know the results of a given referendum question, but you never expect to query a single voter's voting record. In what way does the nature of the application affect your design judgment about privacy, and what effect would that have on normalization considerations?

2. Rewriting history with git

You've getting ready to submit a pull request to the coolapp repo. You branch contains two commits: M, followed by N. The lineage is this:

@developit
developit / *constant-locals-loader.md
Last active February 4, 2022 17:15
Inline Webpack CSS Modules classNames, reducing bundle size. https://npm.im/constant-locals-loader

constant-locals-loader for Webpack

This loader optimizes the output of mini-css-extract-plugin and/or css-loader, entirely removing the potentially large CSS classname mappings normally inlined into your bundle when using CSS Modules.

Run npm install constant-locals-loader, then make these changes in your Webpack config:

module.exports = {
 module: {
@swyxio
swyxio / chatscroller.jsx
Last active November 15, 2020 21:55
Handy Scroll window manager component for building a Slack-like Chat experience - when you want your chat window to autoscroll down when new messages appear, BUT not while you're scrolling up. Also useful for feedlike or log display components. from ryan florence workshop chat example (course at https://courses.reacttraining.com/courses/517181/…
function ChatScroller(props) {
const ref = useRef()
const shouldScrollRef = useRef(true)
useEffect(()=> {
if (shouldScrollRef.current) {
const node = ref.current
node.scrollTop = node.scrollheight
}
})
const handleScroll = () => {