Flatiron Blogger Magazine

Markov Chain Sentences by on 12/03/2017
Letting Computers Speak For ThemselvesWhat is a Markov chain?If we’re going to talk about Markov chains, it’s probably helpful to know what they are. Named for mathematician Andrey Markov, they are a collection of random variables indexed in some way (usually by time), that change from state to state in a way that is dependent solely on the current state, and not past events.That’s a lot of abstract concepts to absorb. It’s probably easiest to think about with some concrete examples, the first of which is borrowed from our old friend, Wikipedia.Imagine a game where you begin with $10 and flip a coin, winning $1 on heads, and losing $1 on tails until your money is gone. After any number of flips we can look at your current pool of money — say, $8– and make a prediction of the next state of your funds — either $7 or $9– with a 50% chance of being correct. No amount of knowledge of prior flips or the starting $10 affect our odds of guessing correctly, making this a Markov chain.Alternatively, let’s say you’re pulling socks from your dresser drawer one at a time, since no one has the energy to find each sock a mate after doing laundry. You set aside each sock you pull out, hoping to find a matching pair (you regrettably bought a few different colors). After several minutes of sock-pulls, your ability to predict the next sock is influenced greatly by the prior pulls, making this a non-Markov chain. Say you have one green pair, two blue pairs, and nine red pairs, and you look at the ground and see a green sock, two blue socks and no red socks. You can say with some confidence you’re going to pull a red sock next.Who cares?So why is this post titled Markov chain sentences? Sentences aren’t coin flips or socks. As I said before, these chains are indexed lists of variables, and in a sentence’s case, the variables are words, indexed by their place in the sentence.The probability of the word’s appearance — like the 50/50 odds of the coin flip — is dependent on something called n-grams. An n-gram is a grouping of n words as they appear together in a source text. In this article we’ll be talking about bigrams, pairings of two words. The sentence “stupid is as stupid does.” Has bigrams of (stupid is), (is as), (as stupid), and (stupid does.)Bigrams are used to predict the next word in a sentence based on a selected word. If we start with “stupid” we can see there are two options, (stupid is) and (stupid does.). There is a 50% chance of either since we don’t know where we are in the sentence. If we pick “is”, then we check any bigrams that start with “is”, and we know with 100% certainty the next word is “as”, because there is only one bigram. We end up at (as stupid), and make the same 50/50 guess as before. If we went with (stupid does.) that would end our sentence, leaving us with “stupid does.” as the whole phrase.You see this behavior a lot with predictive text. If you’ve ever just clicked the suggested word on your phone’s keyboard you can string together some crazy sentences. Here’s an example from my phone:I’m gonna try to watch boss baby girl who was running the ad in my feed because of the soft bed and I’m excited to see me and I was wondering if you are getting loud notifications of copyright law that the Thursday night football song has to be a horrible experience.Not a terrible sentence! The Thursday night football song is a horrible experience. Please ignore the part where I’ve said the phrase “Boss Baby” enough for my phone to suggest it for me. The phone is drawing from the pool of everything you’ve ever typed and pairing words together in a way to save you a little time.So what would something like this look like, behind the scenes? I’ve written a simple version in Ruby to emulate this behavior.The Code:https://medium.com/media/ad4f5e71165f94e6059ce3ec02565d58/hrefWhat is this doing, exactly?If you know Ruby and want to test this out yourself, click the link below the code to see the GitHub repository. It contains additional paragraph and essay methods that run the sentence method multiple times.Lets take a quick look at each of the functions.initialize — We initialize our chain with an array of every word from the inputted text in order. Additionally, we use #find_enders to grab all words that end sentences so we can cheat a little to avoid ending our sentences on words like “the”.make_sentence —This method calls upon #find_next a few times, and then takes all the words returned from that, capitalizes the first, and appends one of the words from our enders array with a period.find_next — Most of the heavy lifting is done here. We pass in a word, then run through our array of all source words, and everywhere we find a match we return the word immediately following our input. This gives us a collection of words that should make sense to follow the original. If nothing is found ( either there wasn’t a word passed in, or the document ended after the input word) it will return a random word from the source file.But wait, shouldn’t you–Yes, there are a lot of opportunities to improve this! We should be making sure our words are all in the same sentence. As-is, the code ignores periods when creating bigrams, leaving some strange transitions. We are also faking our bigrams a bit, as they could exist as a comprehensive dictionary to draw from. The sentence ending method is a bit ham-fisted.This could also extend to larger groupings beyond bigrams — our sentences all come out quite nonsensical, and additional context in the form of trigrams could help words find more natural homes.There are a hundred other things we could change. What matters most, though, is we have a baseline to work with. Let’s see it in action.Making SentencesLet’s set up a new chain and have it generate a sentence with the following snippet:chain = MarkovChain.new(filepath)chain.make_sentenceFor a source file, let’s input the first set of paragraphs from this article and see what we get.“Since no red sock next sock two blue pairs and not past events thats a green laundry.”You can see why we’d want to add some updates. A quick scan and it might make sense, but it’s rather incoherent. Luckily we avoided any mentions of the Boss Baby.A True ExpertIn the process of writing this post I’ve begun to wonder– with all this research, why am I the one writing the post if I’m still learning? There are people who actually know what they’re talking about out there. So I thought, why not let them all write something together? With the help of my program, some of the brightest researchers of Markov chains have combined their writings. The problem with academic writing is that it’s a bit dry. To inject some levity and more flowy prose, I mixed in the text from a ClickHole article about George R. R. Martin’s history with horses while writing Game of Thrones.Click here for enlightenment.Sources for generated article:ClickHole: When I Started Writing ‘Game Of Thrones,’ I Didn’t Know What Horses Looked LikeResearch Papers: 1, 2, 3, 4, 5
Markov Chain Sentences: An Autobiography by on 12/03/2017
By David’s ComputerContextKnow enough to this allows multiple peaks in one section beak. Handling general dirichlet process mixture component is substantially faster than those obtained using these life. Anyone noticing inevitably though there were some kind but i known GAs. My mind oh okay i must have had absolutely no horse using creatures.My new approach extends gibbs sampling for many of methods. Various types of the creatures for many passages describing dothraki GAs. By without anyone noticing inevitably though there were some details i actually looked rest. Local optima metropolis coupled mcmc allows us to entrapment in his satchel and variable-length gas operators. Implementations of the cost of finding the transition probability of the rate of the method speculation. Estimation of horses even more my ignorance as an exact schema theory just consciously refraining from billboard.And variable-length genetic algorithms gas which can effectively approximate posterior distribution wrong. Man despite what horses neck is markov chain is based on distribution. Passages describing dothraki horses were some people assume that can be solved by using the (MCMC). Know that no idea what roose bolton thought overall horse. Ive learned even more efficient than those obtained using the associated markov chain noticing. Uniform equilibrium distribution of the lagrange dual of operators the notions used distribution.Horse it was to entrapment in the rate of trees while difference. With the two new knowledge has a way these indicators by using the core of kings graph. See that can effectively approximate posterior probability matrix in both programming models message passing knowledge revelation. Finding the fastest mixing reversible markov chain is a partial form of the crossover. The edges say 1000 using standard implementations of phylogeny revelation. Between the following when i could have joffrey a variety of finding the corresponding notions used string. Picture of mcmc can be formulated as to easily compute the fastest mixing rate well. The landscape of finding the way these methods for gp uniform crossover terrifically.Using a group of edges say 100000 edges say 1000 using two adjacent vertices the gp like. Allows multiple peaks in retrospect i knew horses since then billboard. The fastest mixing rate as the absence of mcmc mc3 the core of graph. Specifics about horses were some details i hope readers will notice the offspring are time. Horses color shape or disposition i always wrote parameters. Transition probability distribution of gp crossover we present an fingers. Extends gibbs sampling the book of the lagrange dual fingers.
Creation of a Ruby Gem by on 12/10/2017
Rothko: The Pinnacle of ArtFor a technical explanation of the gem, click here, or for more information on how to make your own gems, click here.A wise man once told me that all programming is just breaking problems down to other previously solved problems. And thanks to gems, you don’t even have to be the person that solved the problem. In my ruby programming career I’ve used my fair share of gems — I lean heavily on pry to explain why my code isn’t as flawless as I led myself to believe, rspec to run tests, and so many more that I watch fly past in my terminal as bundler installs them.But one thing that always bugged me is where are all of these coming from? Who made these? What did they even do to create them? I assumed it was some ancient wizard programmers who, after thousands of years of study finally attained the arcane powers of gem creation. For a while I was happy to leave it at that.Until I made something cool. I REALLY wanted to add graphics to my command line app and ASCII wasn’t going to cut it. I know, the idea has a bit of a “spitting-in-the-face-of-God” vibe, but I was consumed by the thought. There were some gems out there offering functionality close to what I needed, but they were either broken or diverged too much from my vision.So I made it myself. I now had this code that could take in a PNG file and spit out beautiful color pixel art at any resolution, as long as your imagination stops at about 100 pixels wide. But that’s high-def for terminal. The program has its flaws — the limit of ANSI colors hold it back, leaving a lot of images looking muddy.Leonardo would not be flattered.I’ve found some workarounds, fiddling with color settings after putting the image out to the terminal, but that defeats the purpose of the program to a degree.Adjusting ANSI colors to improve image with RothkoThe key, I’ve discovered, is to create art intended for the terminal– using its limited palette can be frustrating, but you can get some really cool results if you put in the time. The image below is a screenshot of my terminal.Now THIS is art.So now what? I alone can make that image appear on my computer. What about the next programmer that comes along that wants to make pictures in terminal in spite of it being the worst possible program to do that in?I realized, it was time for me to make a gem. Did I have what it took to ascend to high-wizardhood, or could this be a much simpler process than I’ve made it seem?It turns out it’s super easy.Rubygems.org has a guide → Make Your Own GemBut even easier is if you have bundler guide you along the way and set up all of your files. All you need to do is add your code and edit the .gemspec file with personal information.Bundler guide → Developing a Ruby GemThe first challenge was coming up with a name. I wanted to convey that I was making art, but “Terminal Art” sounded a bit dry. So I turned to my art history knowledge and decided that I was making work similar to Mark Rothko – painting squares.My only big hiccup was not realizing I needed a “spec.files” row in my .gemspec file. I created a completely empty gem more times than I’d care to admit which led to a lot of frustration.Once I had my gem built I created an account on rubygems.org and pushed my gem up. I downloaded my gem maybe once or twice while testing things out. Imagine my surprise when I refreshed my profile page and saw this:My 100 favorite people.I felt like a celebrity. How did all these people even find my gem? They might just be robots that automatically download every gem, but there’s probably another fellow meat popsicle in that number that’s now using my code to make a picture.My code was riddled with errors, and as of writing this I’ve already pushed up my third patch. However, a quick look at pry’s page shows that they’re also on their third patch, so maybe I’m just keeping pace with the greats.If you’re curious about the rothko gem you can find more here:GitHub Repo • RubyGems.orgOr, just add the gem to your next project!
Rothko Gem Explained by on 12/11/2017
Making a Ruby Gem With Bundler by on 12/11/2017
Making a ruby gem is a simple task — the hard part is finding a piece of code you think is important enough to share with the world.For more detailed guides check out the rubygems.org guide or the bundler guide.To get started, make sure you have the bundler gem installed by running this in your terminal:gem install bundlerYou can make gems without bundler, but it makes the process a whole lot easier and will be the method I outline here.The next command we run is:bundle gem YOUR-GEM-NAMECheck out the rubygems.org guide on naming.By running that command bundler will have created a new directory in the active directory.Open up the .gemspec file to get started. It should look something like this:Fill these out with your information and information about your gem.Make sure your files are included in the specification with:spec.files ['FILE-PATH']Right now that’s probably ‘lib/YOUR-GEM-NAME.rb’.If you have any other gem dependencies, make sure to include them by adding this in the specification:spec.add_dependency "GEM-NAME"Add your class or module to the generated file in the lib directory. This is the functionality that people will get when they use your gem!Once everything is set up run this in your terminal:gem build YOUR-GEM-NAME.gemspecThis will create a gem file in the current directory.Now, you might be tempted to publish now, but there is still some work to do. In terminal run:gem install ./YOUR-GEM-NAME-0.1.0.gemThe numbers at the end may vary– that’s your version number, which should have defaulted to 0.1.0.Now open IRB in your terminal and type:require 'YOUR-GEM-NAME'If it returns true, that means it’s been successfully installed!At this point you should make an account on rubygems.org.From there, set up your ~/.gem/credentials file by running the command found at the bottom of your rubygems.org edit profile section under “API access”.After that, just run:gem push YOUR-GEM-NAME-0.1.0.gemAnd your gem will be available for the world to use!
More OO Design: Open/Closed Principle by on 12/11/2017
No coding project is an island by on 12/11/2017
Last week I was challenged to create my first big coding project. We were paired off with a classmate, and asked to create a command line CRUD application. For the uninitiated, this means that we needed to create an application that asks a user to enter information into the command line in their terminal. Then, that information is stored in a database. The user should have CRUD abilities — they can Create new entries, Read the data they’ve already submitted, Update or correct anything they’ve entered, or Delete their information completely.Up until this point, I’d only done one smaller project with another classmate. All other labs or projects I’d been doing on my own. I really enjoyed pair programming on the first project, and was excited to dig into something deeper.My partner David and I created a simple game called Presidential Thunderdome, Vol. 1: Eagles of Screaming Freedom. You can view the finished product here.While it may seem simple, the process had many more steps than I originally anticipated. This was how we organized the three days.Brainstormed ideas together. We used an improv comedy technique called “Yes And” — rather than shooting down or listing the problems with an idea, we listed all of the possibilities. We created a list of about 10 ideas.We narrowed our list down to our favorite two, then asked classmates for feedback. We ended up with a game where two users would choose a squad of five presidents, and have them compete against each other in low stakes challenges.Planned it out. One piece of advice our instructor has told us is to first design a skateboard, rather than trying to create a hovercraft on the first try. We had a big plan for what we’d like the game to do, but started simple. We decided we would start by having users create a profile or access their profile when logging in. Then, they should be able choose to view information about past games, start new one, or quit.We created three classes to start — Users, Presidents, and Games. They would then be associated with a Squad and Game Pick join class.Got on the same page with Github.We decided that David would be a collaborator on the project, and hosted it on my Github. After a few close calls, we decided to create branches rather than working on the master, so we didn’t overwrite the main file.We committed our changes every time we made a big change, or one of us was physically leaving the room, so we would always have the most up to date copy.Programmed together instead of splitting up the work.We chose to work together on all programs, which worked well and allowed us to speed through most of the big stuff. If we worked separately and merged later, I think the process may have gone slower with just one set of eyes to catch bugs or syntax errors.Wrote code that worked, then looked for ways to simplify.Sometimes one of us would get hung up on whether the code we were writing was “right” or the best way. It’s easy to get stuck for too long when thinking this way. We soon got into the rhythm of writing ugly, long methods that worked, and then thinking of ways to refactor. There were often ways to give responsibility for a few lines to a helper method, or to define it in another class.Slowly built our hovercraft.Once you have your skateboard, or the skeleton of the program, you can then start adding functionality. We slowly built the ability to create or retrieve a first player, then add a second player, then have them choose teams of presidents and compete in the challenges.Asked for user feedback.When we had what we felt like was a perfect project, we asked classmates and friends to test it out. This step helped uncover problems we hadn’t considered. For instance, it was possible to have a team of five Ronald Reagans, and after the first round the game would get stuck in an invalid input loop. We also clarified the directions and the general flow of the game.Although it’s simple, I’m very proud of the game that I had a part in building and learned how to work on one problem with one person for a long time. I felt like this was a good introduction to what a real job may feel like. I can’t expect to get a set of short problems every morning to work through on my own; in some jobs, I will need to work with team mates to fix more complex problems. I’ll leave with some last tips:Communication is key.Make sure you and your partner are on the same page each step of the way! Clarify who will do what task. Take time to explain what you’re doing rather than typing silently. Ask questions when you don’t understand what your partner is doing. Be patient. Be positive.Commit often.I’d recommend working on separate branches to avoid overwriting changes, and merging at least once a day. Be explicit about what work you plan to do alone, and make sure you upload any changes so you don’t leave your partner in the dark.Don’t oversimplify your code. When refactoring, remember to not make your code so concise it’s no longer readable to humans. Don’t sacrifice brevity for clarity. And, when you do, make sure to leave a comment describing what an unclear piece of code does.(This is more specific to Ruby)Happy coding!
Going Mobile: From React to React Native by on 12/11/2017
Or Equals in Ruby by on 12/08/2017
TEST by on 11/28/2017
testing
4 ways to improve your ruby coding experience by on 12/08/2017
While we may know our craft well there’s always something more to learn and more ways to improve. in this post I will be discussing 4 ways to improve your coding experience mainly while testing or building code.1. Use ls in Pry to review available methodsEveryone has had that moment where they can picture the method they need but cant remember the exact word(s) used to call the method. Normally at this point one opens their browser and goes to Ruby Docs. Searches by the class the method applies to (wait was it an enumerator?). With one simple Pry command you will never have to leave your terminal to perform such a task. Enter pry’s [ ls ] command.This command only works for pry not irbThis command will list all available methods for any class you choose. As with most commands there are a plethora of flags available to us. For listing methods we will us the [-m/-M ] flags. The lowercase [ -m ] flag will show all methods for instances , and the uppercase [ -M ] flag will display all enumerable methods and instance method a class has.2. Use ri in Pry to see documentationGreat! I believe i’ve found the methods I was looking for but now i’m missing a vital piece of information. I need to see how the method works and if there are any special arguments I can give. Back to Ruby Docs? Nope there is another command in Pry just for this occasion . Enter the [ ri ] command.No but you can easily see what methods are available to you now find out what these methods can do.You can call a Class (ri Array) itself or the Class with one of its methods (see above)By calling [ ri ] with any ruby class or method we get quick access to it’s documentation.Warning: This will require that you have Ruby Version Manager installed which you should. Once you have RVM you will need to run [rvm docs generate]. This will pull the documentation onto your computer.3. Use the Faker gem to easily create dataHave you ever found yourself needing to think of a large amount of values when testing your code? In one case I needed to create 20 instances of a User class and for each of those classes I needed to think of a name, age, address, etc. While random generator site can help alleviate this process. The more data you’ll need the more annoying it will become to constantly generate-copy-paste. Enter the ‘faker’ gem.With the faker gem it will be a breeze to test databasesThe faker gem has a vast amount of values you can generate, all formatted and well documented allowing for easy modification. Due to the random values provided it can also allow you to spot potential errors that could have been missed. Now you can spent less time thinking of names and more time coding.4. Use .pryrc to create custom Pry commandsHave you ever found your self constantly entering the same Pry command? When rapidly testing changes to my code, one of the greatest annoyances was having to constantly exit and renter Pry. However once again Pry comes to our rescue.Every time a pry is started it will look in your home directory and project directory for a file called “ .pryrc ”. Any code in this file will always be executed be before beginning the pry. Have a variable or method for testing that needs to be defined in each pry? Set it in the .pryrc and you’re good to go! There is a large variety of settings and customizations you can make here, but for now lets get our custom command set up.This… changes… EVERYTHING!By having this code in my project’s .pryrc try I now have a pry command called r which will allow me to quickly reload and reenter the pry for my project.By using the 4 tips above not only will coding be a more pleasant experience. it will also increase your workflow. This post covers a very small amount of each topic if you want to learn more please visit the links below.ls -M:https://github.com/pry/pry/wiki/Command-system#Invoking_commandsUsing ri:https://rvm.io/https://github.com/pry/pry/wiki/Documentation-browsing#RiFaker:https://github.com/stympy/fakerPryrc:https://github.com/pry/pry/wiki/Pry-rchttps://github.com/nixme/pry-debuggerAbout Me (Dec 5, 2017)Hi there I’m Marvin. Coding has always been passionate hobby of mine. Since I was a kid building programs always excited me. I would spend my days messing around with C++ HTML JavaScript and Blitz3d.While I found coding fun I only considered a hobby and never chose to pursue it as a career. Recently I made the choice to attend Flatiron School a 15 week coding bootcamp and commit myself to becoming a developer.While I may not be a professional developer yet I will be making these blog post to not only help others but also you share my knowledge. Exciting times ahead! Stay tuned, Marvin out.
Shhhh... It's a Rails Secret by on 12/07/2017
How did I get here? by on 12/07/2017
How urban internet infrastructure worksThe internet is a wild and wonderful place, and seems like connecting to it is seamless, tidy, and easy. But actually, the infrastructure for the internet is old, and fragile.Originally cables were laid for telegraphs in the 1850s, then later for voice communications, and nowadays they’re fiber-optic lines carrying internet traffic. Network infrastructure is not anything new. In 1854, installation began on the first transatlantic telegraph cable, which connected Newfoundland and Ireland.This undersea cable was quite a feat, and actually broke while being laid three times, and the project had to start over. The project began in 1854 and was completed in 1858. The cable functioned for only three weeksThe first official telegram to pass between two continents was a letter of congratulations from Queen Victoria to the President of the United States James Buchanan on August 16. Signal quality declined rapidly, slowing transmission to an almost unusable speed. The cable was destroyed the following month.In the 1800s, data transmission was very limited by size of message as well as speed of transmission. A 500-letter message took nearly 18 hours to transmit across the Atlantic.Now submarine cables are laid very differently.The cables are larger with more protective coating, and have gone from metals to fiber optics.And unfortunately are vulnerable to all kinds of attacks. From sharks, to faulty cables being snapped, and being targeted in wars.Shark cableNow these cables connect the whole world. To date, there are nearly 350 cables laid.When they get to land, they are connected to cable landing points, and routed to different internet providers. There are 983 landing points around the world.What happens when it gets to your city?There are 7 landing points in New York.Brookhaven, NYNorthport, NYHempstead, NYLongbeach, NYMastic Beach, NYNew Rochelle, NYShirley, NYOnce the cables have landed they are often routed to the service providers main hubs, or directly to a city main hub and divided there.60 Hudson Street in Lower Manhattan provides colocation services to over 100 carriers — companies that own the physical equipment that makes up the Internet — including financial exchange and application providers, content and cloud providers, and multiple private enterprises. Interconnectivity is the act of physically linking network equipment with those owned by another company or a customer.Cabling InfrastructureOriginal NYC cabling infrastructure was aboveground.But in the great blizzard of 1888, most of the telegraph cabling infrastructure was destroyed, and all of New York City’s cabling was moved underground where is still is today.Today you can find thousands of miles of cables laid underground in New York. Many manhole covers in NYC aren’t sewer but cables.And orange spray paint on the ground will tell you what it is.In these manholes there are interconnected junctions that take the larger direct cables and split them to direct them to different buildings.Before there was coaxial internet (what many of us have in our homes) we only had telecommunications cables.Telco wiring pairsSo many!That look like this. Each one of those colored cables is a pair that connects directly to your home, and then back to the telecom company’s main hub.What connected telco looks like in a large apartment buildingNow these internet connections for large buildings are shared and not direct back to the main hub, but connected by junctions and other exchange points.How the internet gets in a current day buildingOr thisThen gets distributed to a low voltage panel that routes it to your apartmentTypes of CableCopper Originally used for telegraphy and telephone communications starting in the 1880s. It’s used less and less for internet connections today, partly because it can’t carry as much information as newer types of cable.Coaxial A coaxial cable still has a copper conductor, but is more insulated and more efficient than older copper wires. It’s commonly used for cable television connections. A lot of residential buildings still rely on coaxial connections, connecting up to fiber networks in utility cabinets on the street or underground.Fiber Optical fibers are transparent strands of glass that transmit data as pulses of light. It offers a far faster speeds and greater bandwidth for transmitting information than copper and coaxial. It’s been a part of large-scale telecommunications infrastructure since the 1970s, but fiber connections to residential buildings.What does this mean for internet speedsThere are two types of internet connections you can get from a provider, and shared connection and a dedicated line.Dedicated Internet is exactly what it sounds like: Internet access and bandwidth dedicated to one user and one user alone. It is a line or pipe run directly from a junction point in the street. Whether this allotted bandwidth is fully used or under-utilized, the bandwidth belongs to that user alone.Shared Internet is probably what your business and home are equipped with right now; a single Internet service shared among users, which can then be accessed on various devices and internal networks. On a shared Internet connection, all bandwidth (20 Mbps, 400Mbps, etc.) is split among all users and devices. With shared Internet access, all data is transmitted over one network, consuming away more and more pieces of bandwidth as more devices are connected and types of data are transmitted.So this means even if you are paying for 400Mbps it is ‘best faith’. The more people who are using the shared line in your building or junction will affect you speed.Currently you can get connection speed of 10Gbps (10,000Mbps) over copper wires, which is the coax that most of us use. If you buy the best plan from Optimim of 400 Mbps, you will only be using 0.4 Gbps of the 10 Gbps that is shared on one line.Fun Facts:The Verizon Building at 375 Pearl street once housed all the servers for Wall St.Sources:10Gbps over a copper telephone line: A new world record set by Bell Labs - ExtremeTechHow the Internet works: Submarine fiber, brains in jars, and coaxial cablesInto the vault: the operation to rescue Manhattan's drowned internethttp://www.crainsnewyork.com/article/20140407/TECHNOLOGY/304069996/crossed-wires-untangling-nycs-broadband-undergroundCities 101: Decipher the Hidden Internet Infrastructure of NYC's Streets with New Guide Networks of New York - Untapped Cities
My time with Progressive Web Apps by on 12/07/2017
One Gem to Load Them All by on 12/06/2017
At the outset, we fledgling, enthusiastic — perhaps naive, by and by wild — Rubyists are typically asked to compose small bits of code inside a single .rb file, yet are handed a magical, prebuilt project folder replete with exacting spec folders, environments, program controllers, rake files, and all manner of additional helper material, in which to do so. Rspec tests pass and fail, we Pry smack into the middle of a broken method, we connect to our little database as spoilt children, never taking turns going without, never knowing what it means not to have a gemfile.As we progress through lessons, as through lyfe, part of our task is to become familiar with all that has been provided for us by our mentors — to all those who came before us — to pay respects, and to understand, for we will one day be responsible for all of it.Today we’re going to look at one library of code we students see in our projects every day, try to understand what it does and how, and pay some damned respect: Bundler.One Gem to Find Them…What do we do exactly, when we want to add a bunch of pre-written code to our application?If we’re students, we might copy a small amount of it from the text of our code-along lag and paste it into an .rb file just before we need it, like common criminals.https://medium.com/media/a263722b2504a236fde26789379d4f57/hrefSeems fine for a tiny amount of code, but what if we need a bit more? Maybe we save it in a file, and arrange for the file to be opened and evaluated somewhere in our app before we need it:require ‘../config/environment.rb’Feelin’ that.But what if we’re the instructor of an object-oriented programming course and need to provide our students’ projects with a lot of someone else’s prewritten code to help them along? Instead of a file, our project might require a Ruby gem’s worth of someone else’s code:gem install 'rspec'Sick. My computer has the most recent rspec library installed locally. I can find and add all that code to my project:require 'rspec'When we have a whole bunch of code to add to our project, we locate an appropriate Gem (by default on RubyGems.org), install it locally, and require it in our project… boom. Done. With all the code in the rspec gem saved to our local machine and subsequently loaded into our project, we can easily include tons of english-readable tests to help our students along. No issues, forever and ever. POST OVER.Except there’s a few details nagging the curious student:Maybe you couldn’t help noticing the rspec gem itself seemed to require the installation of some other gems. Guess the code in the rspec gem itself relied on some code in some others. Peculiar. Probably the first and only time that’s ever happened — those rspec people are really smart programmers after all. I wouldn’t worry about it.Maybe the version of the rspec gem you installed required the installation of specific versions of some other gems you’ve never heard of. Like: really specific versions. Like “if you were to inexpertly load a newer version of any of them, the rspec gem might not work too good” levels of specific. Each of them.Wait… which version of rspec did we even load? Were there multiple versions available on RubyGems?Fig 2: 1 + 168 versions of rspecCome to think of it, we’ve been studying code for like 5 seconds, and our projects already need a lot more code than just rspec:require 'sqlite3'require 'activerecord'require 'rspec'require 'pry'require 'organgrinder'require 'boxcar'require 'veal'require 'student-brains'require 'rest-of-lab'If each of those gems has a dependency — or more realistically, several dependencies — on a specific version of some other Ruby gem, how in Glenn Danzig would you be able to ensure that you’re adding in versions of each gem that all play nicely with one another? What if the (totally made-up but probably existent) “veal” gem depends upon the installation of an “activerecord” gem version that is newer than what your current “sqlite3” gem can handle?Ask someone who was there. See if you have what it takes to pay those kind of dues.One Gem to Bring Them All and in the Gemfile.Lock ThemAll this brings us to Bundler. Bundler asks us to store a source to check (rubygems.org) and a list of gems we’d like to install in a file named Gemfile in the root of our project folder.source "https://rubygems.org"gem "sinatra-activerecord"gem "sqlite3"gem "pry"gem "require_all"gem "rest-client"gem 'json'In exchange, Bundler gives us a way to require the gems specified therein, enumerating each gem’s dependencies, computing (and saving, for the sake of your collaborators) a list of compatible versions of everything you are asking to add, loading only the compatible versions, in one line of code:require bundler/setupRequiring using the “bundler/setup” option not only installs compatible versions of all gems and dependents in your Gemfile and preserves the magic combination in Gemfile.lock, it actually limits the lookup of required gems to those listed in the gemfile, helping prevent others from requiring an incompatible, or perhaps unavailable, gem elsewhere in the project.Among other things, Bundler allows you to namespace your Gemfile and require select groups of gems:Bundler.setup(:default, :development)Either way, Bundler makes a known-working list of compatible gems easy to distribute to your collaborators (missing something? Type Bundle Install), and prevents others from requiring Metallica-lyric-spewing gems elsewhere in your load path.In a talk at RailsConf 2015, Bundler 1.16 co-author Andre Arko offered this succinct breakdown of what running Bundle Install instructs your computer to do, which I’ll embellish here:Read the Gemfile (and Gemfile.lock, if it’s there)Ask RubyGems.org for a list of every version of every gem listed thereinAs needed, resolve all gem dependencies: find gem versions allowed by the Gemfile that all work together in righteous harmonyIf found, write down the list of properly reconciled gem versions in Gemfile.lock, for the sake of humanity, current and future project contributorsInstall the appropriate gem versions as needed until every gem in the lock is installedGems versions in your project gotten a little stale over time? Run Bundle Update. It’ll re-resolve all dependencies for all gems in the Gemfile again, based on the latest versions of all gems available at your source.The oldest release of Bundler available on RubyGems dates to July 29, 2009, credited to one Yehuda Katz. 210,000,000+ downloads later, there is an explosion of Ruby development, and we neophytes are putting apps together with the most tenuous grasp of what the require method does. Thank you for your generosity, Yehuda!Sources:Bundler: Bundler setupHow Bundler Works: A History of Ruby Dependency ManagementGem Versioning and Bundler: Doing it RightUnderstanding Bundler's setup process
URL Helper Methods by on 11/28/2017
This topic is one that I knew nothing about. Consequently, I began researching it like a young girl might go skipping through a meadow picking flowers on a warm sunny day: excited and giddy. But quickly, the skies darkened, the flowers died, and the meadow became a swamp of muddy quicksand that swallowed me whole. That is to say, this topic is a beast. A fascinating, ever inspiring beast, but one that should not be taken on lightly.Bellow is the flake of a fraction of the tip of the Machine Learning iceberg that I was able to grasp over a couple days research, and an initial peak at it’s relationship to Ruby.What exactly is Machine Learning?Machine Learning is in fact as intuitive a term as it appears, and more than that, it’s applications are almost second nature to us.Machine Learning is a subset of Artificial Intelligence. It consists of Algorithms or models coded to observe and retain patterns in existing data. Then based on those patterns, learn to predict similar behaviors in new data.Exciting A-List Machine Learning:Self-driving Google Car. AWESOME. The very definition of ML.Every day applications:Online recommendation offersFraud detectionFacial recognition, like on FacebookEmail spam filtersetc.This feels almost ridiculous in it’s simplicity. This is something we’ve done since birth: observe behaviors, their outcomes, and adjust accordingly. But the magnitude of it’s applications in technology are anything but simple. Before we get into some more nitty gritty, lets look at a quick history of Machine Learning and why it’s become so popular in recent decades.Quick History:1950’s-1990’s: Machine Learning research is primarily knowledge-driven, that is to say, it focused on teaching computers to act more like humans. Starting in 1950, Alan Turing creates the “Turing Test” to see if computers can possess actual intelligence akin to that of a human. In 1952 Arthur Samuel created the first computer learning program which taught the computer to play checkers, and get better on it’s own as it observed more and more winning game patterns.1990's-Present: Machine Learning programs are primarily data-driven, meaning they are written to analyze data and draw conclusions, or learn, from the patterns it encounters.Contributing factors to more Data-Driven programming:More data available than ever before.Affordable processing powerInexpensive storageBayesian LogicIn my initial reading I kept encountering references to something called Bayesian Logic. After a little digging, it became clear that this is the back bone of Machine Learning programs, particularly as they pertain to data analysis.Don’t freak out, it’s simpler than you think. Kind of.Named after it’s creator, Thomas Bayes, Bayes’ Law is a means of quantifying uncertainty through conditional probabilities. For example, finding the probability of event A happening given that event B has already taken place. A more real life application might be determining the probability of a document falling under a certain category. Here is where we use Bayes’ Law:This theorem can be overwhelming, but here is a basic breakdown of what this is saying:P(A|B) reads what is the probability of A, given B. Lets use an example of someone with a sever illness, like mad cow disease. We are trying to figure out the probability that the patient has mad cow, A, given their observed symptoms, B.P(B|A) In order or to determine the overall probability, we first need the probability of a patient having these symptoms, B, given that they already have mad cow, A.P(A) We then multiply that probability by the probability of someone having mad cow at all, A, possibly considering where they live, their age, health, etc.P(B) This piece of the puzzle is only necessary when using Bayes’ Law to determine classification. This is the constant, it is simply the likelihood that any human at any given time, would display the observed symptoms. It’s not necessary to calculate probability. It is however necessary to calculate comparative probabilities, like in a classifier method.Using our example, the equation would look like this:We would use this to determine the probability of a number of people with symptoms and classify them based on that probability. This is the skeletal logic behind classifiers. Essentially the more encounters a program has with examples of each outcome, the better and more detailed its ability to determine any one individual’s likelihood of having mad cow, given their symptoms.The depth of this topic is a dark black infinite ocean of awesome that I am completely without the tools to explore at this point in my programming journey. However there are a few awesome blogs and videos I found that go into greater but still novice-friendly detail:For a quick 5 min, but extremely helpful explanation of Bayes’ Law, click here.For a longer more in depth but equally helpful and interesting explanation of Bayes’ Law and its relationship to classifier programs, click here.How can I use this in Ruby?Well luckily in our field of professional apathetics, a ruby gem was created to do all of this fascinating logic for you. It was constructed by Lucas Carlson and David Fayram II, to allow for Bayesian and other types of classifications, including LSI, or Latent Semantic Indexing.Two of the most common classifications used by this gem are Naive and LSI.A Naive Bayesian Classification is one in which the probability of an occurrence is not determined by the outcome of occurrences before it. For example, the roll of a dice. Each time you roll it, the probability of getting a 6 is 1/6, regardless of the number rolled before it. Or in the case of a spam classifier (the favorite example of everyone to ever teach classifiers), it would treat every word in an email as unique and unrelated to the words around it.Whereas in an LSI Classification it would learn to recognize, say, the subject of an email as “Vintage Car Sale” and learn to expect certain words such as “car”, “engine”, “price”, etc. It can identify context for certain words, generate predictions based on those observations, and hone those predictions to become sharper with each classification it performs.Below is the code for running these classifications in ruby:To install you simply require ‘classifier’ and run ‘ruby install classifier’I read through a incredible blog that breaks down the process for generating your own naive classifier method, and it’s a great way to understand the long hand of what this gem accomplishes for us.All in all, I found out just enough to know that what I understand is nominal compared to the vast universe of Machine Learning research and information. But it has certainly peaked my interest and I’m excited to continue exploring!
ELI5- A Simple Blockchain. by on 11/28/2017
For some reason, this morning I found myself watching this interview from the mid 90s with the late Steve Jobs. He recalled his early experiences as a budding technologist growing up in the pre-internet Silicon Valley. He remembered feeling empowered by do-it-yourself electronics kits . “It gave oneself the sense that one could actually BUILD the things that one found oneself around in the universe. These things were not mysteries anymore.” He continues, “it became clear that the technologies around us were the result of human creation and not just these magical things that appeared in ones environment.”As a student of programming and a generally curious person, I find it rewarding to try and interface with technical concepts that are beyond my pay grade. More often than not I find that I actually can engage with such topics using knowledge and terms I do understand. It can be useful when trying to understand something complex to start with a low-resolution representation of a thing and gradually increase the resolution as you learn more.Conversations about cryptocurrency that I’ve sat in on recently have made me realize how little I actually know about the complexities of actual currency. I had heard of “altcoins” like “dogecoin” and was curious about what it would take to build my own altcoin — heath kit style. After some reading, I still feel a little baffled by the whole thing, but I’ve been able to find a point of reference for beginning programming students.Blockchain is the data structure that sits at the heart of cryptocurrencies like Bitcoin, Ethereum, or Litecoin. It’s a form of “distributed ledger” that enables . According to Investopia, “Since ancient times, ledgers have been at the heart of economic transactions — to record contracts, payments, buy-sell deals or movement of assets or property. The journey which began with recording on clay tablets or papyrus, made a big leap with the invention of paper.” When a transaction is made between users, the transaction is recorded in a digital ledger that lives on many different computers all over the world. This is what makes the distributed ledger “distributed”. When a transaction occurs, the exchange cannot be altered because it would need to be authenticated with all the other records. The blockchain ensures that every transaction can happen only once. This problem is essentially what destroyed the record industry. A music listener could purchase and download an album of Mp3s and replicate the album infinitely, thus making the product worthless. This core principle can be replicated in just a few steps.1. Create a Block class.class Block{ constructor(index, data, previousHash ='') { this.index = index; this.time = Date.now(); this.data = data; this.previousHash = previousHash; }}Block objects are going to be the units of our block “chain. We want our block to hold a few things. The index is the blocks position in the chain, time is going to hold the time our transaction occurred, and data is the information we actually want to store. The data that we’re storing on our blocks could depend on what it is we’re trying to secure. We’re going to add more to our block later.2. Create Blockchain classclass Blockchain{ constructor(){ } createGenesisBlock(){ } getLatestBlock() { } addBlock(addBlock){ }}We need our blockchain to be able to do a few different things. We need be able to create the very first block in the chain. We dramatically call this the “genesis block”. We also need to be able to add a block and return the latest block added to the chain. So simple, even your grandmother could do it. Now for the cool stuff.3. Encrypt Data Using SHA-256const SHA256 = require('crypto-js/sha256');class block{ constructor(index, data, previousHash = '') { this.index = index; this.time = Date.now();; this.data = data; this.previousHash = previousHash; this.hash = this.calculateHash(); } calculateHash(){ return SHA256(this.index + this.previousHash + this.timestamp + JSON.stringify(this.data)).toString(); }}We need to give each block a unique identity. SHA is an acronym that stands for Secure Hash Algorithm. They’re used to scramble data irretrievably. Good hash functions should always produce the same hash for the same piece of data, while also generating a very different hash for another piece of data that is closely related. Below, you can see that the SHA224 algorithm scramble an almost identical pieces of data to radically divergent results.SHA224("The quick brown fox jumps over the lazy dog")0x 730e109bd7a8a32b1cb9d9a09aa2325d2430587ddbc0c38bad911525SHA224("The quick brown fox jumps over the lazy dog.")0x 619cba8e8e05826e9b8c519c0a5c68f4fb653e8a3d8aa04bb2c8cd4cIn our code we include a SHA 256 library as well as add a new method to our block class. In calculateHash(), we pass in all of the blocks unique information and generate a new key. COOL!5. Create the chain.class blockchain{ constructor() { this.chain = [this.createGenisisBlock()]; } createGenisisBlock() { return new block (0, "1/1/2017", "GenesisBlock", "0"); } getLatestBlock() { return this.chain[this.chain.length - 1]; }}Our createGenisisBlock() instantiates and returns a new block with some dummy data. In our blockchain class constructor, we initialize a new array with and hold in it our genesis block. A getLatestBlock method will help us grab the information we need (the previous block’s hash) from the previous block.class blockchain{ constructor() { this.chain = [this.createGenisisBlock()]; } createGenisisBlock() { return new block (0, "1/1/2017", "GenesisBlock", "0"); } addBlock(newBlock) { newBlock.previousHash = this.getLatestBlock().hash; newBlock.hash; this.chain.push(newBlock); }}In addBlock(), we take in a newly created block, grab the previous block’s hash, create the block’s own unique hash, and push the new block onto the chain. All together now!const SHA256 = require('crypto-js/sha256');class block{ constructor(index, data, previousHash = '') { this.index = index; this.time = Date.now(); this.data = data; this.previousHash = previousHash; this.hash = this.calculateHash(); } calculateHash() { return SHA256(this.index + this.previousHash + this.timestamp + JSON.stringify(this.data)).toString(); }}class blockchain{ constructor() { this.chain = [this.createGenisisBlock()]; }createGenisisBlock() { return new block (0, "GenesisBlock", "0");}getLatestBlock() { return this.chain[this.chain.length - 1]; } addBlock(newBlock) { newBlock.previousHash = this.getLatestBlock().hash; newBlock.hash; this.chain.push(newBlock); }}let gregCoin = new Blockchain()gregCoin.addBlock(new Block(1, "Some data"));gregCoin.addBlock(new Block(2, "Some more data"));gregCoin.addBlock(new Block(3, "Even more data"));console.log(JSON.stringify(gregCoin, null, 4));Output"chain": [ { "index": 0, "time": 1511878280780, "data": "GenesisBlock", "previousHash": "0", "hash": "04c9044530bb5b86951fca793e35ac328580d447103ecdf49401a1ec64e96397" }, { "index": 1, "time": 1511878280782, "data": "Some data", "previousHash": "04c9044530bb5b86951fca793e35ac328580d447103ecdf49401a1ec64e96397", "hash": "f995dcd166d7b069ca45452a4d95da57665c25245664e0356949b2d8b9d4c9bb" }, { "index": 2, "time": 1511878280782, "data": "Some more data", "previousHash": "f995dcd166d7b069ca45452a4d95da57665c25245664e0356949b2d8b9d4c9bb", "hash": "adba47b825e420083739533bbfd83858ae115e3897772fc187880b6b8ab0ae59" }, { "index": 3, "time": 1511878280782, "data": "Even more data", "previousHash": "adba47b825e420083739533bbfd83858ae115e3897772fc187880b6b8ab0ae59", "hash": "d1bac18b6f43fd4d30834a6671baf6386bf51da030af237c576dee12da619eea" } ]
The Deep Web != The Dark Web by on 11/29/2017
Courtesy of CNNtechRrecently as a student time at Flatiron School, we moved on from basic Ruby to Ruby on Rails and have have began to learn a little bit more about the servers, the internet, and how to create basic websites. A large portion of students in this program will likely end up working with the internet in some aspect, and yet, there’s so little I know about it. I decided for the topic of this blog to explore three aspects of the ‘Deep Web’ and ‘Dark Web’ that seem to come up most:Deep Web:What is it?Where does it exist?How can I access it?Dark Web:How does it connect to the Deep Web?Is is it legal?How can I access it?DEEP WEBDespite it’s Sp00ky name, the deep web is simply a name for describing the entirety of the internet. Let’s take a second to think about what we’ve learned in our class so far. Google is a search engine, a lister or indexer, that gives the user a list of the pages that fall within the parameters he or she have given to the search engine. It will also search by follow links between sites. For example, when you search for ‘beef’ google will pull up websites related to the topic of beef:Turns out, the “beef” isn’t that hard to findWhen a user clicks into a site on google, it gives you a static page, or a webpage like this one. What a search the user’s search for beef isn’t providing are dynamic sites. Google will not go any deeper than the information on the page, or in other words it won’t go through or ‘behind’ the search engine.Thus if I were to search for ‘beef’ on USA.gov, the following page would not be accessible to the search engine.This second page is, in theory, a part of the Deep Web. The Deep Web is, simply put, the part of the internet that is not accessible through a search engine. It also comprises the majority of the internet! Any information that is behind a paywall, is protected by password , or anything that is generated dynamically and does not have a permanent URL is a part of the deep web, as it is not accessible to the surface scrapers.You actually access the deep web routinely, every day. The emails in your Gmail account, your online bank statements, your office intranet, direct messages in Twitter, photos you’ve uploaded to Facebook and marked as private. These are all the deep web.’ — Andy BettsFunnily enough, the vast majority of the internet is comprised of these kinds of sites:DARK WEBhttps://medium.com/media/1bdeb630acf24519310a835caf7edbf9/hrefThe Dark Web, unlike the Deep Web is not consisting of websites that are not searchable by google, but aren’t accessible at all unless you have a special router that masks your computer’s information. The most popular of which is Tor.Originally called “the onion router”, Tor is a free service that directs internet traffic through several thousand relays, or overlay network.Onion routing is implemented by encryption in the application layer of a communication protocol stack, nested like the layers of an onion. Tor encrypts the data, including the next node destination IP address, multiple times and sends it through a virtual circuit comprising successive, random-selection Tor relays. Each relay decrypts a layer of encryption to reveal the next relay in the circuit to pass the remaining encrypted data on to it. The final relay decrypts the innermost layer of encryption and sends the original data to its destination without revealing or knowing the source IP address. — Wikipedia ‘Tor’This works to protect information because each intermediary only knows the preceding and following locations that the information is being sent to.Source: WikipediaThe Dark web has become the home to many kind of things, from illegal activity to the site of information dumps by dissidents. To avoid being traceable most ‘leaks’ are done on the dark web.But how do you know where to look? That’s the bigger question. When you download Tor, it comes with a modified Firefox search engine. But no directory at all. A user has to navigate to Tor Directory, all of these sites accessed through Tor will have a .onion ending.That’s a spicy meatball!Thus to recap, the Deep Web is another name for the ‘unsearchable’ or part of the internet, while the Dark Web, while unsearchable , may be accessed through the use of a onion-router. While the Dark Web is certainly an unsavory topic, I think it’s important to understand the internet, encryption, and how they work!https://medium.com/media/73af0d96ea82a548379f046c7bfa7aca/href
Big O Notation: A Basic Guide to Complexity by on 12/04/2017
As a newbie programmer, I’ve often encountered moments during coding where I’ve thought to myself, “wow, I just wrote some really ugly code, I wonder just how inefficient my program is.” Sometimes this thought might be triggered by numerous lines of repetitive code, or nested loops of unnecessary complexity. As someone who is motivated by aesthetics and efficiency, I pressed it upon myself to do more research to find out what elegant code looks like so that one day I can hopefully write code that I can be proud of and that hopefully, others will enjoy reading as well. As I scoured the internet for best practices and other sources of wisdom, I came across the concept of Big O Notation, which turns out, is a rather useful and important concept to be aware of when thinking about algorithms and computational complexity.So what is Big O Notation?Technically, Big O Notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. In computer science, Big O Notation is applied and used to describe the complexity of an algorithm. The notation O is used because the rate of growth of a function is also called its order, and N is used to denote the problem size of the given function.The efficiency of a program can be measured by CPU (time) memory, disk, or network usage. This can be broken up into performance and complexity, with performance referring to how much time or memory or disk is used when a program is run, and complexity referring to how the resource requirements of a program or algorithm scale.Essentially, Big O Notation is asking, what happens to the resource requirements as the size of the problem gets larger? What is the rate of growth for the time it takes to complete a problem? These are important questions to ask when writing algorithms. Differences in time and resource consumption may seem minute when comparing a data set size of 10 to 100, but what happens when that data set grows from 100 to 10,000? 10,000 to 1 million? Can your program still run and complete in a feasible amount of time?Complexity can be broken down into the relation of the number of operations to the problem size. We are always interested in the worst case scenario. For example, if the algorithm is a search algorithm for an unsorted set, we are interested in what happens when the desired search item is the very last item of the unsorted set. What is the maximum number of operations that might be performed in this case? And again if the size of the set tends towards infinity?Consider this problem:def print_first_item(arr) puts arr[0]endThe complexity of this algorithm would be considered O(1), or constant time.Basically, if you were to graph the amount of time it took to solve this problem versus the size of the problem set, or in this case the array, the corresponding graph would be a horizontal straight line. This is because no matter the size of the array, the function just requires one step, or one operation, to run and therefore will always execute in the same time and space.Now consider a binary search algorithm with a sorted array.A binary search works by taking the middle item of a data set, and checking if the desired search item is larger or smaller than that given middle. If the given middle is larger than the desired search item, the search will continue in the left half of the array, and vice versa. The search will continually halve the data set and repeat this process until the array cannot be halved anymore.This type of algorithm is described as O(logN). The relationship between size and time in this case is logarithmic. Because the algorithm cuts the problem size in half each time, doubling the problem size will not correspond to a doubling of the time required to complete the program. As the input grows larger, the change in time required for the operation grows negligible, as illustrated below by the red curve. This makes logarithmic type algorithms extremely efficient for large data sets.source: https://cs.nyu.edu/~acase/fa14/cs101/hw/hw5/O(N) — linear timeNow consider the blue curve. O(N) operations run in linear time, as in for each additional input unit, an additional unit of time is required. An example of an algorithm in linear time is finding an item in an unsorted list.def is_item_in_list(arr, i) arr.each do |el| if el == i return true end end return falseendEssentially, for each element in the problem set, you are doing a constant number of operations, so the time required for the program to run will increase linearly with the size of the problem set.O(N²) — Quadratic TimeO(N²) represents algorithms where the execution time is proportional to the square of the input size. What does this actually look like?def nested_loops(n) (1..n).each do |x| (1..n).each do |y| puts x, y end endendI find it easiest to visualize this in nested loops. For each X in range(n), I must complete the action puts x, y n times. If n was 2, the computation would happen 4 times, and if n was 4, the computation would happen 16 times. Every time you increase the number of elements, the computation time will increase proportionally to the square of the input size (n*n).Other examples of algorithms that also perform in quadratic time are bubble sort, selection sort, or insertion sort.O(N!) — Factorial or Combinatorial ComplexityThis type of algorithm involves doing something for all possible permutations of the n elements. As a result these operations run in factorial time and quickly become impractical for any large input size n.An easy way to visualize this is the classic traveling salesman problem, which asks:“Given a list of cities and distances between each pair of cities, what is the shortest possible route that visits each city only once and then returns to the origin city?”The naive solution is to check all possible routes to calculate the shortest route. While that seems plausible if given 3 cities, imagine the explosion in possibilities when you increase the number to 10 cities, and then to 100.source: https://xkcd.com/399/This is just a very brief overview of Big O Notation and thinking about computational complexity. For a graphic summary, see the below graph, taken from Big-O Cheat Sheet.Additionally, below are sources that helped me greatly in processing this information, please check them out for more information!http://web.mit.edu/16.070/www/lecture/big_o.pdfBig-O Algorithm Complexity Cheat Sheethttps://stackoverflow.com/questions/487258/what-is-a-plain-english-explanation-of-big-o-notationA beginner's guide to Big O notation
Understanding Recursion by on 10/25/2017
Recursion is a topic in programming that may be hard to first understand the first time that you encounter it. Even the second, third, and fourth times too. It’s one of those topics that a developer might find themselves using other solutions that do the same thing to simply avoid it. Recursion is essentially the process of calling a function within a function, a method within a method.You may want to think about recursion like being on the surface of the ocean, on a boat, out in the middle of the west pacific ocean. I’ve chosen that spot because somewhere in that region lies the world’s deepest trench, the Mariana Trench. This visual reputation of ocean depth represents the depth of a file or the relation of information relative to the current scope you are operating out of. Now that we are sailing the pacific, imagine a treasure chest that is somewhere in this trench at any point below you. You would need to know how far down you would need to go to retrieve this chest, and luckily for you have a transmitter that tells you when to stop looking. This ‘transmitter’ is basically the statement in your code that would tell and recursive method/function to stop running and finally return a value. Normally if a programmer knew where is file was he would just iterate down to that level in order to retrieve his file but this concept plans for when you don’t necessarily know how far in your file is. Often times we are burdened with the task of finding a file or specific bit of data that can be nested so far inside the first scope we don’t where to find it. This is where recursion comes in handy.At its core, a recursive call is supposed to have two key things. A conditional where the function is going to stop calling itself and a conditional where the function is going to call itself. Relating this back to my ocean reference, the transmitter statement is notifying that it has reach the end of the reoccurring part of the function. In the case of the chest, the second part is you actively going to get this chest once you know where that transmission signal is coming from. You might be thinking that what I just described sounds like a simple if/else statement and you’d be right! The difficult part is understanding knowing when to stop it and when to kept the function calling itself. The key to that is thinking about the problem backwards or on a smaller scale. This concept works really nicely with numbers so let’s take a look.The fibonacci sequence is a great way to demonstrate the usefulness of recursion. As defined in the picture above, the fibonacci sequence is a series of numbers where the next number is dependent on the sum of the two numbers that come before it. It starts from 0 being the first number and 1 being the second number. The third number is then also 1 because 0 plus 1 is still 1. In this example the function is asking you to get the value of the next number in the series. To get the next number you would initially need to know the number that you are currently at and the number right before that one. Since the fibonacci sequence starts at zero you would have to start from 0 counting up all the numbers in between to figure out what the two numbers would be adding together. To add two numbers together we would have to start at the first two numbers in the sequence. We want our transmitter condition to say that if the number is a 0 or a 1 we just want those to be our values because this will be our stopping statement.That will tell us the next number in the sequence for 0 and 1. With recursion the function will not start executing until it get to this bottom layer. That basically means that until the function will call itself inside on its self until it reaches this stopping point in the code. For example if the number we are given is 6, the function won’t return a value until our number is less than or equal 1. Once it has a return value the function can then start executing code, working its way back up to the scope you started in so that you can return a value. Each level that the code is finally running it will then start to add up the numbers that we want. Because of this, your ‘go’ condition has to have a way of calling itself with a different value, a value that is eventually going to reach that first condition. In my example that would look something like this.Great! Now we have decrementing values on our conditional that will eventually tell our program to stop. Lastly, we want our program to be the result of two numbers added together. We need to first think small and backwards from the number given. So if our start position number is 6, answer is 8, we want our program to start add from 0 and 1. Once we reached this we can then add the numbers together using the return values of our function calls.If the program works for 2, it will work for 6 or 10. The recursive properties will do the math for you. Whatever you are tallying or trying to repeat, that function will do it for your so you don’t have to worry about bigger numbers, you just have to worry about the smallest case where this recursive function would apply to. The final return value of the function or method would then be equivalent to you achieving the chest from the depths below.Using this method of solving problems should be limited because at time it can be very straining on the computers temporary memory. This is because the more levels you go down calling the function, it adds a call stack. This call stack could cloud memory and make programs run slowly or even break. If an application had a bunch of recursion calls you can imagine how slow that program would run. This is why developer only use this tactic when they don’t know exactly where they want there program to stop running.the definition of recursionhttps://www.livescience.com/37470-fibonacci-sequence.html
Tackling A Code Project by on 11/08/2017
A very wise and immensely knowledgable female programmer once told me to write and test code for when in it fails, not for when it works because it’s always going to work. This bit of advice to someone who isn’t well versed in programming and code language might find this silly. Why would I purposely break something that is working just fine? That thought is preposterous! Well that thought is why great applications and projects are made. As programmers, it is our job to keep in mind people who are less adept and accident prone. People are going to make mistakes and therefore things will break. Building fool proof applications is not an easy task but with a guideline in place, a programmer can create any application that not only is user friendly but also very elegant to view and transparent to make.As a developer in the making, tackling my first coding project was like trying to build a sand castle for the first time. For me, there was no clear starting point and working with a partner only complicated that more. It wasn’t because my partner was a terrible partner or anything but it was more along the lines that we were both equally as lost as to where to begin our elaborate sand castle. After about a week of tirelessly work my partner and I were finally able to come together to produce a product and in doing so learn some valuable lessons that I’d like to share with you.When building your sand castle, location is key. You want your castle to be in a spot where everyone can see your beautiful, hard work as well as far enough from the water so it won’t be destroyed. As this relates to your code project, this is your audience. Who do you want using your product? Who do you think will use your product? This part should take no more than 10 minutes to think about because then from there you will use that information to form an idea. The next part of your castle is the type of castle you will build. The type of castle relates to the function of your application. Essentially what you are doing. My first application was an NFL game win predictor which compared two teams, in there current state, and predicted a winner in percentage form. My partner and I wanted to appeal to sports analysis and football enthusiasts. If the function of the application is already given to you then thats less time you have to think about a topic and more time you’ll have researching it.Since our metaphor is taking place on the beach, you can think of the beach itself as the internet and each grain of sand a file on the internet. With this in mind our next step is to set up some data that we can pull from the internet to fill our application database. This step can take anywhere from a couple of hours a to a day to complete. It is important to choose a piece of data that will be constant for the rest of your project that way it won’t interfere with later processes. The data you have will dictate the tone in terms of what you application can and cannot do. As a final project, the application you build will access all of these files that are housed with in the database.Now that we have our location, foundation, and materials, we can start the construction of our castle. Sand is not the sturdiest of materials so you have to work in a way that builds off of what you previously built. If you are working in a group or with a partner, it would be beneficial to work together on the same area. You can’t work on the top part of the castle if you partner is still sculpting the first floor. This is the fun part of the code project and should take the most amount of time. Here you are creating the features and configuring how your application will interact which whatever interface its going to have its users on. It doesn’t matter if thats the command line or the web, you are working on the interactivity and design of the product. The features are all of the things that you application will do which is basically your own custom functions/ methods.One you have all the moving pieces in place, the last step is to take a step back and admire the work you have done. You want to circle your castle, looking for any weak points, any points that would possibly crumble your project. In other words test you application for it breaking! You want to purposely try to break what you created because if you so how manage to break, then someone else using the product will definitely break it.Another great pointer when constructing your sand castle is remember to build just the castle and not a village. Start on one thing before you move on to the next. Once you get the castle built and sturdy then you can think about the surrounding pieces or adding on the main structure. After you complete these steps, your product should then be ready to demo to test the working piece on a larger scale. Other developers can add input on things that might need to be tweaked or just give you general praise for your hard work. So now lets recap.Set your goal on a target audienceDevelop an idea that will satisfy your target baseLay the foundation of data to be used for the rest of the projectDevelop the models around the dataSet up the interface to connect to the models and implement the features that you createdBreak the application, smash it to pieces if you can