start new:
tmux
start new with session name:
tmux new -s myname
{ | |
"AL": "Alabama", | |
"AK": "Alaska", | |
"AS": "American Samoa", | |
"AZ": "Arizona", | |
"AR": "Arkansas", | |
"CA": "California", | |
"CO": "Colorado", | |
"CT": "Connecticut", | |
"DE": "Delaware", |
If you're writing web applications with Ruby there comes a time when you might need something a lot simpler, or even faster, than Ruby on Rails or the Sinatra micro-framework. Enter Rack.
Rack describes itself as follows:
Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks.
Before Rack came along Ruby web frameworks all implemented their own interfaces, which made it incredibly difficult to write web servers for them, or to share code between two different frameworks. Now almost all Ruby web frameworks implement Rack, including Rails and Sinatra, meaning that these applications can now behave in a similar fashion to one another.
At it's core Rack provides a great set of tools to allow you to build the most simple web application or interface you can. Rack applications can be written in a single line of code. But we're getting ahead of ourselves a bit.
# This server demo does a socket hijack in Rack and then saves the socket to a global variable | |
# to prevent it from being GCed when the Puma thread ends. It will then write "BEEP" to each | |
# socket every ten seconds to prevent the connection timing out. During testing, it easily | |
# handled up to 65523 connections, after which it ran into the `ulimit` for open file descriptors. | |
# The bit with the waiting area is there because a normal `Set` is not thread safe and it would | |
# drop socket due to race conditions. The `Queue` is thread safe and will make sure all sockets | |
# are preserved. | |
# run with `rackup -q -p 8000 -o 0.0.0.0 c10k.ru` | |
# testing: install `ab` and then run `ab -c 20000 -n 20000 <ip adress of server>:8000/ |
/** | |
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers | |
* @author ShirtlessKirk. Copyright (c) 2012. | |
* @license WTFPL (http://www.wtfpl.net/txt/copying) | |
*/ | |
var luhnChk = (function (arr) { | |
return function (ccNum) { | |
var | |
len = ccNum.length, | |
bit = 1, |
It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media
This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.
Updated for Rails 4.0.0+
Set up the bower
gem.
Follow the Bower instructions and list your dependencies in your bower.json
, e.g.
// bower.json
{
This document is outdated. | |
You should read David Bryant Copeland's excellent online book: http://angular-rails.com/crud_recipe.html | |
--------------------------------------------------------------------------------------------------------------- | |
I think it's better to install javascript/css libraries using Bower rather than gem which is Ruby packager. | |
1. Install Rails 4 and create a new project. | |
2. Install bower(Note you need to install node first.) | |
sudo npm install -g bower |
# excerpt, I've got my stuff in my file | |
source ~/.git-completion.bash | |
source ~/.git-flow-completion.bash | |
export PS1='\w $(vcprompt)\$ ' | |
alias s="git status" | |
alias d="git diff" |