Skip to content

Instantly share code, notes, and snippets.

@kmamykin
kmamykin / mondodb_autoincrement_id.rb
Created January 12, 2011 08:29
How to generate autoincremented int id in MongoDB
# loosely based on:
# http://shiflett.org/blog/2010/jul/auto-increment-with-mongodb
new_id = Mongoid.master["sequences"].find_and_modify
:query =>{"_id"=>"<name of your business entity>"},
:update=>{"$inc"=>{"seq"=>1}},
:upsert=>true,
:new =>true #<-- this causes the new incremented id to be returned
@kmamykin
kmamykin / tasks.rake
Created June 28, 2011 08:26
How to render Rails 3 view in a rake task
task :renderview => :environment do
app = YourApp::Application
app.routes.default_url_options = { :host => 'xxx.com' }
controller = YourController.new
view = ActionView::Base.new(app.config.paths.app.views.first, {}, controller)
view.class_eval do
include ApplicationHelper
include app.routes.url_helpers
end
puts view.render(:template => 'your/action')
@kmamykin
kmamykin / gist:1117047
Created July 31, 2011 18:27
foreman not terminating process
$ cat Procfile
web: rails server thin -p $PORT
$ gem list | grep foreman
foreman (0.19.0)
$ ps aux | grep thin
kmamykin 13773 0.0 0.0 4156 864 pts/2 S+ 14:22 0:00 grep thin
$ foreman start
14:22:36 web.1 | started with pid 13897
14:22:50 web.1 | => Booting Thin
14:22:50 web.1 | => Rails 3.1.0.rc4 application starting in development on http://0.0.0.0:5000
@kmamykin
kmamykin / Gemfile
Created August 3, 2011 13:51
heroku run rake assets:precompile
gem 'rails', '3.1.0.rc5'
gem 'thin'
gem 'foreman'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
@kmamykin
kmamykin / Gemfile
Created August 4, 2011 08:28
Rails 3.1.0.rc5 setup for heroku with assets pipeline working
gem 'rails', '3.1.0.rc5'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass', '3.1.5' # <= downgraded due to a weird interaction b/w compass blueprint and latest Sass
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
gem 'uglifier'
gem 'compass', :git => 'https://github.com/chriseppstein/compass.git', :branch => 'rails31'

#Introduction

Several layers of css rules:

  • Base: resets, normalize, base colors, typography, etc.
  • Layout: header, footer, wrapper, grid, sidebar, main-column
  • Modules: avatar, buttons, upvote, forms
    • States: (defined with the modules) somemodule-active, somemodule-disabled, -selected
    • Themes: (defined with the modules) somemodule-primary, somemodule-large

Module

Keybase proof

I hereby claim:

  • I am kmamykin on github.
  • I am kmamyk (https://keybase.io/kmamyk) on keybase.
  • I have a public key whose fingerprint is A867 CC04 0B98 F741 1C95 FAB6 68E1 E361 656B 844C

To claim this, I am signing this object:

@kmamykin
kmamykin / .gitignore
Last active January 29, 2016 22:48
Exploration of Monad ideas in JavaScript
/node_modules
@kmamykin
kmamykin / RRKbMa.markdown
Last active June 29, 2016 20:13
React Star Wars Characters
@kmamykin
kmamykin / README.md
Last active February 13, 2017 18:23
Site pre-rendering options

Introduction

What is prerendering? Pre-rendering a JavaScript heavy website refers to the process of using a proxy that loads the requested page and runs all JavaScript on the page, and then returning the content of the rendered page as the response to the page's request. The advantages of doing so are twofold:

Performance

Perfomance of the site is greatly improved as the browser is able to render the page without waiting for external scripts to load and external data api requests to finish. In Brickwork client site that means requesting a store page returns HTML that is already rendered with all the data about the store.

After the initial page HTML is rendered from the response, the browser asycronously request JavaScript scripts that load in the background, query the API for data and re-render the page in browser, adding interactivity to the page. Ideally the page pre-rendered on the server/proxy and the page rendered in the user's browser will be exactly the same (given the api data hasn't chang