-
cin.get -
cin.unget -
getline(cin, var) -
cin >> var -
coutis slow because it has to go to the operating system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Idiot solution to this dailyprogrammer idea | |
| # <http://redd.it/yln9p> | |
| puts """abandonments | |
| abbreviating | |
| abbreviation | |
| abbreviators | |
| abecedarians | |
| aberrational | |
| abjectnesses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The most readable way (in my opinion) | |
| $(document).ready(function() { | |
| // your code here | |
| }); | |
| // Alternate way that's supposedly faster | |
| $.fn.ready(function() { | |
| // your code here | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Destructive selection sort. | |
| # [1, 12, 8, 5].selectionSort() | |
| Array::selectionSort = -> | |
| # Look forward from each element. | |
| for num, i in this | |
| # Find the smallest element in this partition. | |
| smallest = null | |
| smallestIndex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Non-destructive merge sort. | |
| # [1, 8, 12, 5].mergeSort() | |
| Array::mergeSort = -> | |
| # If the array has one element, we're done. | |
| return this if @length is 1 | |
| # Split the array in half. | |
| halfwayMark = Math.floor(@length / 2) | |
| firstHalf = @slice(0, halfwayMark) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Test my hypothesis that Object.is(a, b) is the same as a === b. | |
| // Log an error if they're different. | |
| var numTests = 0; | |
| function test(a, b) { | |
| if ((Object.is(a, b)) !== (a === b)) { | |
| console.error('Object.is is different from === for ' + a + ' and ' + b); | |
| } | |
| numTests ++; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Non-destructive quicksort. | |
| # DOESN'T WORK WITH DUPLICATES. Too lazy. | |
| # [1, 5, 8, 12].quickSort() | |
| Array::quickSort = -> | |
| # Is the array already sorted by nature of its length? | |
| return this if @length <= 1 | |
| # Pick a pivot as a random element. | |
| # This is probably not the best pivot we could choose. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <style type="text/css"> | |
| body { | |
| -webkit-user-select: none; | |
| -khtml-user-drag: none; | |
| -khtml-user-select: none; | |
| -moz-user-select: none; |
Let's first talk about booleans, which you might already know, so I apologize if this is review. If you think you understand booleans completely, skip this puppy.
A boolean is a variable type in many programming languages. It usually that something can be true or false, yes or no, on or off, 0 or 1.
I imagine booleans like lightswitches. They can either be on or off -- true or false.
Most languages have true and false, but they vary somewhat. C++ writes true and false, where Python has capitalized True and False. CoffeeScript supplements the classics and adds yes, no, on, and off. C kinda doesn't have them built-in, you have to make your own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Load dependencies | |
| var express = require('express'); | |
| var is = require('browseris'); | |
| var fs = require('fs'); | |
| // Build me an app! | |
| var app = express(); | |
| app.set('port', process.env.PORT || 3000); | |
| app.use(express.compress()); |