Skip to content

Instantly share code, notes, and snippets.

View goodbedford's full-sized avatar

goodbedford goodbedford

View GitHub Profile
@goodbedford
goodbedford / js
Created April 12, 2017 06:32
gb-eslint.config.js
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
@1UnboundedSentience
1UnboundedSentience / find maximum contiguous sequence of 1s in an Array of 0s and 1s, given that you can change k number of 0s to 1s
Last active February 22, 2016 02:24
find maximum contiguous sequence of 1s in an Array of 0s and 1s, given that you can change k number of 0s to 1s
def max_contig(array, k)
max_len = 0
sliding_window = []
window_start = 0
potential_len = 0
array.each_index do |idx|
p "#{idx} #{sliding_window[0]}---#{sliding_window[-1]}"
potential_len += 1
if array[idx] == 0
sliding_window << idx
import React from "react";
import { render } from "react-dom";
const ParentComponent = React.createClass({
getDefaultProps: function() {
console.log("ParentComponent - getDefaultProps");
},
getInitialState: function() {
console.log("ParentComponent - getInitialState");
return { text: "" };
// Bonfire: Title Case a Sentence
// Author: @goodbedford
// Challenge: http://www.freecodecamp.com/challenges/bonfire-title-case-a-sentence?solution=function%20titleCase(str)%20%7B%0A%20%20%0A%20%20var%20strArr%20%3D%20str.split(%22%20%22)%3B%0A%20%20var%20tempArr%20%3D%20%5B%5D%3B%0A%20%20%0A%20%20strArr.forEach(function(word)%7B%0A%20%20%20%20var%20firstChar%20%3D%20word%5B0%5D.toUpperCase()%3B%0A%20%20%20%20word%20%3D%20word.toLowerCase()%3B%0A%20%20%20%20word%20%3D%20firstChar%20%2B%20word.slice(1)%3B%0A%20%20%20%20tempArr.push(word)%3B%0A%20%20%7D)%3B%0A%20%20%0A%20%20return%20tempArr.join(%22%20%22)%3B%0A%7D%0A%0AtitleCase(%22I%27m%20a%20little%20tea%20pot%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function titleCase(str) {
var strArr = str.split(" ");
var tempArr = [];
// Bonfire: Check for Palindromes
// Author: @goodbedford
// Challenge: http://www.freecodecamp.com/challenges/bonfire-check-for-palindromes?solution=function%20palindrome(str)%20%7B%0A%20%20%20%20str%20%3D%20str.toLowerCase()%3B%0A%20%20%20%20str%20%3D%20str.replace(%2F%5B%5Cs%2B%2C.%5C%5C()_%5C%2F-%5D%2Fg%2C%20%22%22)%3B%0A%20%20%20console.log(str)%3B%0A%20%20%20tempStr%20%3D%20str.split(%22%22).reverse().join(%22%22)%3B%0A%20%20%0A%20%20for%20(%20var%20i%20%3D0%3B%20i%20%3C%20tempStr.length%3B%20i%2B%2B)%7B%0A%20%20%20%20if(tempStr%5Bi%5D%20!%3D%3D%20str%5Bi%5D%20)%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%0A%20%20%2F%2F%20Good%20luck!%0A%20%20return%20true%3B%0A%7D%0A%0A%0A%0Apalindrome(%22eye%22)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function palindrome(str) {
str = str.toLowerCase();
str = str.replace(/[\s+,.\\()_\/-]/g, "");
console.log(str);
tempStr = str.split("").reverse().join("");
@OfTheDelmer
OfTheDelmer / queue.md
Last active September 11, 2018 19:48

Interview Prep

Control Flow And Queue's

A queue just preserves the order in which items arrived into it. This helps model real world problems around waiting in your turn or in line.

Directions: Write a ruby script to do the following with a queue.

Scenario: you have a store and you're writing a script to help calculate a quick receipt. The one problem is that every 3rd and 5th item a customer buys is on sale. Every 3rd item is 10% off and every 5th item is 20% off, but also, an item that is both a 3rd and 5th item is 30% off.

@nolanlawson
nolanlawson / protips.js
Last active February 4, 2024 18:06
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@alicial
alicial / mock-service-example.js
Last active June 10, 2019 14:26
AngularJS: Setting up a mocked service to use in controller unit tests.
// Mocked Service
angular.module('mock.users', []).
factory('UserService', function($q) {
var userService = {};
userService.get = function() {
return {
id: 8888,
name: "test user"
}
@jopotts
jopotts / default_values.rb
Last active August 13, 2022 16:26
Simple default values on creation of ActiveRecord models
module DefaultValues
def has_default_values(default_values = {})
class_attribute :default_values
self.default_values = default_values
after_initialize :assign_default_values
include InstanceMethods
anonymous
anonymous / index.html
Created November 3, 2012 09:15
A CodePen by Justin Windle. Equations for Organic Motion - Experimenting with various equations to simulate organic movement / patterns of motion. This is a test sheet created for quick prototyping for another experiment.
<h1>Equations for Organic Motion - Test Sheet</h1>
<div id="more">
<span class="arrow">&#8593;</span>
Resize for more
</div>