Skip to content

Instantly share code, notes, and snippets.

// Bonfire: Missing letters
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-missing-letters?solution=function%20fearNotLetter(str)%20%7B%0A%20str%20%3D%20str.split(%27%27).map(function(c%2C%20i)%7B%0A%20%20%20%20%20%20return%20(c.charCodeAt()%20!%3D%20str.charCodeAt()%20%2B%20i)%20%3F%20String.fromCharCode(str.charCodeAt()%2Bi)%20%3A%20%27undefined%27%3B%0A%20%7D)%3B%0A%20return%20str.lastIndexOf(%27undefined%27)%20%3F%20str%5Bstr.lastIndexOf(%27undefined%27)%2B1%5D%20%3A%20%27undefined%27%3B%0A%20%09%0A%7D
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function fearNotLetter(str) {
str = str.split('').map(function(c, i){
return (c.charCodeAt() != str.charCodeAt() + i) ? String.fromCharCode(str.charCodeAt()+i) : 'undefined';
});
return str.lastIndexOf('undefined') ? str[str.lastIndexOf('undefined')+1] : 'undefined';
// Bonfire: Sorted Union
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sorted-union?solution=function%20unite()%20%7B%0A%20%20%2F%2FImportant%3A%20You%20should%20not%20slice%20on%20arguments%20because%20it%20prevents%20optimizations%20in%20JavaScript%20engines%20(V8%20for%20example).%20Instead%2C%20try%20constructing%20a%20new%20array%20by%20iterating%20through%20the%20arguments%20object%0A%20%20args%20%3D%20new%20Array(arguments.length)%3B%0A%20%20for(var%20i%3D0%3B%20i%3Carguments.length%3B%20i%2B%2B)%7B%0A%20%20%20%20args%5Bi%5D%20%3D%20arguments%5Bi%5D%3B%0A%20%20%7D%0A%20%20args%20%3D%20args.reduce(function(a%2Cb)%7B%0A%20%20%20%20return%20a.concat(b)%3B%0A%20%20%7D)%3B%0A%20%20return%20args.filter(function(a%2Ci)%7B%0A%20%20%20%20return%20args.indexOf(a)%20%3D%3D%20i%3B%0A%20%20%7D)%3B%0A%7D%0A%0A%0A%0A%0Aunite(%5B1%2C%203%2C%202%5D%2C%20%5B5%2C%202%2C%201%2C%204%5D%2C%20%5B2%2C%201%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function unite()
// Bonfire: Spinal Tap Case
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-spinal-tap-case
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return str.replace(/([a-z][A-Z])|\s|_/g, function(match){
return match.length === 2 ? match[0] + "-" + match[1] : "-";
// Bonfire: Sum All Odd Fibonacci Numbers
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-odd-fibonacci-numbers#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function sumFibs(num) {
return fib(num).reduce(function(a,b){
return b % 2 ? a + b : a;
});
}
// Bonfire: Sum All Primes
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sum-all-primes#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function sumPrimes(num) {
var primes = [];
for(var i=2; i<=num; i++){
if(isPrime(i)) primes.push(i);
}
// Bonfire: Smallest Common Multiple
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-smallest-common-multiple#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function smallestCommons(arr) {
var nums = range(arr[0], arr[1]);
return nums.reduce(lcm);
}
// Bonfire: Steamroller
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-steamroller
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function steamroller(arr) {
var flattened = [];
function flatten(a){
return Array.isArray(a) ? a.forEach(flatten) : flattened.push(a);
}
// Bonfire: Binary Agents
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-binary-agents
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function binaryAgent(str) {
return str.split(' ').map(function(e){
return String.fromCharCode(parseInt(e, 2));
}).reduce(function(a,b){
return a+b;
// Bonfire: Everything Be True
// Author: @codebubb
// Challenge: http://www.freecodecamp.com/challenges/bonfire-everything-be-true
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function every(collection, pre) {
// Is everyone being true?
return collection.every(function(e){
return Object.keys(e).indexOf(pre) !== -1 && e[pre];
});
@codebubb
codebubb / ruby_mail.rb
Created February 1, 2016 08:50
Send secure mail with Ruby mail
# Make sure the mail gem is available first:
# gem install mail
require 'mail'
Mail.defaults do
delivery_method :smtp, {
:port => 465, # Change this if your provider requires a different port for SSL
:address => "<yourSMTPServer>",
:user_name => "<yourUserName>",
:password => "<yourPassword>",