Skip to content

Instantly share code, notes, and snippets.

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.
@dasibre
dasibre / gist:6468189
Created September 6, 2013 18:45
array inject method
hash = [[:first_name, 'Shane'], [:last_name, 'Harvie']].inject({}) do |result, element|
result[element.first] = element.last
result
end
@dasibre
dasibre / gist:6700242
Created September 25, 2013 14:14
javascript form button for each object
#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
@dasibre
dasibre / gist:6786245
Last active December 24, 2015 10:48
basic ujs issue
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:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
//Point A
int count = 0;
while (count < 100){
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
//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
@dasibre
dasibre / Gemfile
Created December 12, 2013 17:16 — forked from peterhellberg/Gemfile
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"
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!');
// 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) {