This guide will get you started using Spark on Heroku/Cedar. Spark is basically a clone of Sinatra for Java. 'Nuff said.
Create a single Java main class in src/main/java/HelloWorld.java:
:::java
import static spark.Spark.*;
import spark.*;
| require 'rubygems' | |
| require 'sinatra' | |
| require 'redis' | |
| # To use, simply start your Redis server and boot this | |
| # example app with: | |
| # ruby example_note_keeping_app.rb | |
| # | |
| # Point your browser to http://localhost:4567 and enjoy! | |
| # |
| ids = [1,2,3] | |
| def targs(*ids) | |
| puts ids.length | |
| puts ids.flatten.length | |
| end | |
| targs ids | |
| #=> 1 | |
| #=> 3 |
Dear Rubyists,
I just lost a contract because of my code in a Rails project.
The specific code in question is related to a "posting a comment" feature. Here are the details:
In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.
The "senior developer", whom is the stake holder's right hand man, said this:
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
Compress 1K bytes with Zippy ............. 3,000 ns = 3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns = 20 µs
SSD random read ........................ 150,000 ns = 150 µs
Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs
| <div itemprop="image" data-picture="lazy" data-alt="Don't forget to change the alt text!"> | |
| <div data-src="assets/images/example-s"></div> | |
| <div data-src="assets/images/example-m" data-media="(min-width: 700px)"></div> | |
| <div data-src="assets/images/example-l" data-media="(min-width: 1200px)"></div> | |
| <noscript> | |
| <img src="assets/images/example-s.jpg" alt="Don't forget to change the alt text!"> | |
| </noscript> | |
| </div> |
This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.
The script is here:
#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"
| hash = { 'foo' => 'bar' } | |
| # Version 1 | |
| hash = Hash[hash.map { |k, v| [k.to_sym, v] }] | |
| # Version 2 | |
| hash = hash.reduce({}) do |memo, (k, v)| | |
| memo.tap { |m| m[k.to_sym] = v } | |
| end |
... or Why Pipelining Is Not That Easy
Golang Concurrency Patterns for brave and smart.
By @kachayev