This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log = [ | |
{time: 201201, x: 2}, | |
{time: 201201, y: 7}, | |
{time: 201201, z: 2}, | |
{time: 201202, a: 3}, | |
{time: 201202, b: 4}, | |
{time: 201202, c: 0} | |
] | |
I want to collapse the array of hashes into this, all the hashes with the same time: should be merged into one. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hash = [[:first_name, 'Shane'], [:last_name, 'Harvie']].inject({}) do |result, element| | |
result[element.first] = element.last | |
result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is my player partial | |
.w-col.w-col-3.w-col-small-6 | |
= image_tag player.image_url.to_s | |
h4= player.full_name | |
= link_to "Pin", { controller: "pinboard_players", action: "new", id: player}, remote: true, class: "pinbutton #{player.full_name}" | |
player index | |
.section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new.js.erb file has the following js code | |
$('a.pinbutton').on('click', function() { | |
$(this).parent().append('<%= escape_javascript(render("select")) %>') | |
}); | |
here's the player index with the new link | |
<%= link_to "Pin", {controller: "pinboard_players", action: "new", id: player}, remote: true, class: "pinbutton", id: "#{player.id}" %> | |
controller new action action: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
int main() | |
{ | |
//Point A | |
int count = 0; | |
while (count < 100){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before | |
class Moviegoer | |
attr_accessor :name, :street, :phone_number, :zip_code | |
validates :phone_number, #... | |
validates :zipcode, #... | |
def format_phone_number ; ... ; end | |
def verify_zipcode ; ... ; end | |
def format_address(street, phone_number, zipcode) #data_clump | |
#do formatting, calling format_phone_number and verify_zipcode | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//JS functions, prototypes | |
var ok_for_kids = function(movie) { | |
// or: function ok_for_kids(movie) { ... } | |
return( /^G|PG/.test(movie.rating) ); | |
} | |
ok_for_kids; // => a function | |
ok_for_kids({title: 'The Godfather', rating: 'R'}); // => a function call | |
myfunc = ok_for_kids; | |
myfunc({title: 'The Godfather', rating: 'R'}); // => a function call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem "sinatra", "~> 1.3.2" | |
group :test do | |
gem "minitest", "~> 2.10" | |
gem "rack-test", "~> 0.6.1" | |
gem "capybara", "~> 1.1" | |
gem "capybara-webkit", "~> 0.11" | |
gem "capybara_minitest_spec", "~> 0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkStatus(req, res, next) { | |
As.findOne({ email: req.body.email }, function(err, data) { | |
if (err) { | |
return next(err); | |
} else if ( data === null) { | |
return( next() ); | |
} else if ( data.verifyStatus === true ) { | |
res.send('Your account has already been activated. Just head to the login page.'); | |
} else { | |
res.send('An email has been send before, please check your mail to activate your account. Note that you can only get another mail after 1.5h. Thanks!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: | |
// var express = require('express') | |
// require('enableMultipleViewRoots')(express) | |
module.exports = function(express) { | |
var old = express.view.lookup; | |
function lookup(view, options) { | |
// If root is an array of paths, let's try each path until we find the view | |
if (options.root instanceof Array) { |
OlderNewer