This is the reference point. All the other options are based off this.
|-- app
| |-- controllers
| | |-- admin
| require 'csv' | |
| file = "#{Rails.root}/public/data.csv" | |
| table = User.all;0 # ";0" stops output. Change "User" to any model. | |
| CSV.open( file, 'w' ) do |writer| | |
| writer << table.first.attributes.map { |a,v| a } | |
| table.each do |s| | |
| writer << s.attributes.map { |a,v| v } |
| with | |
| dau as ( | |
| -- This part of the query can be pretty much anything. | |
| -- The only requirement is that it have three columns: | |
| -- dt, user_id, inc_amt | |
| -- Where dt is a date and user_id is some unique identifier for a user. | |
| -- Each dt-user_id pair should be unique in this table. | |
| -- inc_amt represents the amount of value that this user created on dt. | |
| -- The most common case is | |
| -- inc_amt = incremental revenue from the user on dt |
| # Atom Cheatsheet. | |
| # Project Key Bindings. | |
| - 'cmd-shift-p': open the command palette. | |
| - 'cmd-p' or 'cmd-t': open the fuzzy finder to find a file. | |
| - 'cmd-b': look for a file that is already open. | |
| - 'cmd-shift-b': search the list of files modified and untracked in your project repository. | |
| - 'ctrl-0': open and focus the the tree view. |
| require 'net/http' | |
| require 'json' | |
| module Bing | |
| class Search | |
| BASE_URL = "https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Composite?" | |
| SINGLE_QUOTE_ENCODED = "%27" | |
| def initialize(api_key) | |
| @api_key = api_key |
| var http = require('http'); | |
| var sys = require('sys'); | |
| var exec = require('child_process').exec; | |
| var util = require('util'); | |
| var fs = require('fs'); | |
| http.createServer(function(request, response) { | |
| var dummyContent = '<!doctype html><html><head><title>Test</title><meta charset="utf-8"></head><body><p>Hello world!</p></body></html>'; | |
| var htmlFileName = "page.html", pdfFileName = "page.pdf"; | |
HTTP is a stateless protocol. Sessions allow us to chain multiple requests together into a conversation between client and server.
Sessions should be an option of last resort. If there's no where else that the data can possibly go to achieve the desired functionality, only then should it be stored in the session. Sessions can be vulnerable to security threats from third parties, malicious users, and can cause scaling problems.
That doesn't mean we can't use sessions, but we should only use them where necessary.
| # autoload concerns | |
| module YourApp | |
| class Application < Rails::Application | |
| config.autoload_paths += %W( | |
| #{config.root}/app/controllers/concerns | |
| #{config.root}/app/models/concerns | |
| ) | |
| end | |
| end |
| # Ways to execute a shell script in Ruby | |
| # Example Script - Joseph Pecoraro | |
| cmd = "echo 'hi'" # Sample string that can be used | |
| # 1. Kernel#` - commonly called backticks - `cmd` | |
| # This is like many other languages, including bash, PHP, and Perl | |
| # Synchronous (blocking) | |
| # Returns the output of the shell command | |
| # Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |