Skip to content

Instantly share code, notes, and snippets.

@zxbodya
zxbodya / render-react-with-rxjs.md
Last active November 1, 2021 08:49
React with RxJS, reactive way :)

Observable React elements with RxJS

Note: if you want to skip history behind this, and just looking for final result see: rx-react-container

When I just started using RxJS with React, I was subscribing to observables in componentDidMount and disposing subscriptions at componentWillUnmount.

But, soon I realised that it is not fun to do all that subscriptions(that are just updating property in component state) manually, and written mixin for this...

Later I have rewritten it as "high order component" and added possibility to pass also obsarvers that will receive events from component.

@hopsoft
hopsoft / db.rake
Last active May 6, 2024 14:00
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@mateusmedeiros
mateusmedeiros / doodad.service
Last active August 16, 2017 14:09
Systemd services
[Unit]
Description=App running with puma + improvised rvm gemset support
[Service]
RootDirectory=/srv/http
WorkingDirectory=/www/doodad
User=http
Group=http
EnvironmentFile=/etc/systemd/system/doodad.vars
class Profile < ActiveModel::Aggregator
aggregate :user
aggregate :email
def combine
user.save
user.emails.build(email_attributes).save
end
end
@thomasfr
thomasfr / Git push deployment in 7 easy steps.md
Last active May 1, 2024 23:17
7 easy steps to automated git push deployments. With small and configurable bash only post-receive hook
@jswanner
jswanner / gist:1302999
Created October 21, 2011 02:53
Arel example
# before
def self.front_page
where(:front_page => true).select('*, coalesce(position, 999999999) AS position').order('position ASC')
end
# after
def self.front_page
where(:front_page => true).select([
Arel.sql('*'),
Arel::Nodes::NamedFunction.new('COALESCE', [arel_table[:position], 999999999]).as('position')