Skip to content

Instantly share code, notes, and snippets.

Round.find(1).guesses.select(:card_id).where(correct: true).distinct
self.guesses.select(:card_id).group(:card_id).having("count(*) = 1").length
#returns number of correct cards on first guess.
@rrichardsonv
rrichardsonv / 0_reuse_code.js
Created January 12, 2017 20:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
{"latitude":37.8267,"longitude":-122.4233,"timezone":"America/Los_Angeles","offset":-7,"currently":{"time":1493401688,"summary":"Clear","icon":"clear-day","nearestStormDistance":290,"nearestStormBearing":63,"precipIntensity":0,"precipProbability":0,"temperature":63.04,"apparentTemperature":63.04,"dewPoint":44.49,"humidity":0.51,"windSpeed":8.04,"windBearing":339,"visibility":10,"cloudCover":0.17,"pressure":1018.03,"ozone":299.31},"minutely":{"summary":"Clear for the hour.","icon":"clear-day","data":[{"time":1493401680,"precipIntensity":0,"precipProbability":0},{"time":1493401740,"precipIntensity":0,"precipProbability":0},{"time":1493401800,"precipIntensity":0,"precipProbability":0},{"time":1493401860,"precipIntensity":0,"precipProbability":0},{"time":1493401920,"precipIntensity":0,"precipProbability":0},{"time":1493401980,"precipIntensity":0,"precipProbability":0},{"time":1493402040,"precipIntensity":0,"precipProbability":0},{"time":1493402100,"precipIntensity":0,"precipProbability":0},{"time":1493402160,"pre
/*
Copyright 2017 Bryan Keller (https://github.com/widget-)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
/* body{
background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet) !important;
}
p, span, h1, h2, h3, h4, h5, div, section, article, body {
font-family: "Comic Sans MS", cursive, sans-serif !important;
}
.member_image{
-webkit-animation: spinToWin 5s infinite;
animation: spinToWin 5s infinite;
class BloomFilter {
static DEFAULT_HASH_FN(size) {
return (hex) => {
const hex32 = XXH.h32(hex);
return (string) => {
return Math.abs(hex32.update(string).digest().toNumber() % size);
};
};
}
const preorderTraverse = (node) => {
if(!node){
return [];
}
return [node.value, ...preorderTraverse(node.left), ...preorderTraverse(node.right)];
};
const inorderTraverse = (node) => {
if(!node){
return [];
@rrichardsonv
rrichardsonv / maze.js
Created April 27, 2018 22:34
MazeGeneration(might as well be stream of consciousness haha)
// create a function that accepts two paraments: an empty maze and a starting coordinate
// the maze will be an array of arrays of objects. the objects will look like:
// {
// "n": true,
// "e": true,
// "s": true,
// "w": true,
// "visited": false
// }
//
@rrichardsonv
rrichardsonv / tries.js
Created May 2, 2018 22:09
Tries solution
class Node {
constructor(){
this.trie = {};
}
static traverseChildren(word, node){
if(!Object.keys(node).length){
return word;
}
return Object.keys(node)