Skip to content

Instantly share code, notes, and snippets.

@gojun077
gojun077 / gist:3698612
Created September 11, 2012 13:47
CodeAcademy - Review of Functions in JS Sec 2/3, Ex 4/4
/*
3. Argument Types - Part II
Now let's say we want to make sure that the caller always
gets a numeric value back, even if the input wasn't of the
right type.
To achieve that, we need to check the type of the argument
that was passed in. If it wasn't a number, we probably
shouldn't try to multiply it. We'll just return 0 in that case.
*/
@gojun077
gojun077 / gist:3698633
Created September 11, 2012 13:50
CodeAcademy - Review of Functions in JS Sec 3/3, Ex 1/4
/*
1. Parameters are Local to the Function
Each parameter of a function is effectively a variable.
As we saw in the previous lesson, it has a name that we
can use inside the function to refer to the value that
was supplied by the call to the function.
Once the function has been called, is that name available
outside the function? To test this, first run the code as is.
You should see "ERROR: w is not defined". What that means
@gojun077
gojun077 / gist:3698720
Created September 11, 2012 14:02
CodeAcademy - Hello New York, Sec 1/1, Ex 4/5
/*
4. After Dark
The cost of a Taxi ride varies by time of day (we pay
drivers extra to work the night shifts). A flat surcharge
of $0.50 is added to cost for any trip starting at 8pm
and continues until we hit 6am.
Expand your taxiFare function to accept a second parameter
called hourOfDay which represents the time of pickup. Add
a night surcharge of $0.50 during the appropriate hours,
@gojun077
gojun077 / gist:3698754
Created September 11, 2012 14:07
CodeAcademy - Hello New York, Sec 1/1, Ex 5/5
/*
5. You've Arrived at Your Destination
It's been a late night at the office and the company
is footing the bill for your trip home.
Use the taxiFare function you've written to set the
variable tripCost to the cost of your crosstown ride
of 5 miles at 2:00 in the morning.
*/
@gojun077
gojun077 / gist:3706137
Created September 12, 2012 11:53
CodeAcademy - Review Primitives in JS, Sec 1/7, Ex 2/10
/*
2. Looking back at conditionals
Last week we saw how using if else statements allowed us to return
different outcomes for different scenarios.
We also saw how we can use switch statements and ternary operators
to write neater code.
Perhaps the most difficult part of conditionals are nested conditionals.
Let's review this concept again with a simple example.
@gojun077
gojun077 / gist:3714376
Created September 13, 2012 13:43
CodeAcademy - Review Primitives in JS, Sec 4/7, Ex 2/3
/*
2. FizzBuzz Revisited
Now that we know more about Boolean operations, let's return to the
FizzBuzz exercise and explore it a bit more.
We've given you the output we want in console.log(""). All you have
to do is provide the code for the conditions that will result in the
correct Boolean value for each if statement.
Place the right conditions in the right places. Use Boolean operations
@gojun077
gojun077 / gist:3761419
Created September 21, 2012 13:20
CodeAcademy - Recursion in Javascript Sec 2/5, Ex 5/5
/*
Now that we've covered the bare essentials, try rebuilding the
factorial() function we've been working on, but this time write
it all from scratch. To help you along, here are five questions
that you can use whenever using recursion in your code:
-What is/are the base case(s)?
-What is/are the recursive case(s)?
-Have I included any other necessary termination condition(s)?
-Do the statements in the function lead to the base case?
@gojun077
gojun077 / gist:3993618
Created November 1, 2012 13:26
Recursive solution to Fall 2012 MITx 6.00x PS3 #3 Newton's Method
# Problem 3: Newton's Method
def computeRoot(poly, x_0, epsilon):
'''
Uses Newton's method to find and return a root of a polynomial function.
Returns a list containing the root and the number of iterations required
to get to the root.
poly: list of numbers, length >= 1.
Represents a polynomial function containing at least one real root.
The derivative of this polynomial function at x_0 is not 0.
@gojun077
gojun077 / Daum_no_copy.js
Last active January 1, 2016 12:39
New right-click and copy blocking code as of 2013.12.27 from Daum blogs
var contents_article_no = "1234567"; //'[0-9]{7}'
var looping = "0";
var BLOGID= "1AaAAU"; //'[0-9][A-Z][a-z][A-Z]{3}'
var isblock = false ;
isblock = parent.document.getElementById("div_" + contents_article_no).oncontextmenu() || isblock;
if(isblock) {
document.write("<meta http-equiv=\"imagetoolbar\" content=\"no\">");
document.oncontextmenu = function() { return false; };
document.onselectstart = function() { return false; };
document.ondragstart = function() { return false; };
@gojun077
gojun077 / jun_GCJ_2014_1C_PartElf.py
Last active August 29, 2015 14:01
Our code from GCJ 2014 Round 1C Problem A
import math
FILE_NAME = "1C_ProbA_PartElf_small.in"
OUTPUT = "1C_ProbA_PartElf_small.out"
def load_file():
'''
String -> ListOfInt
Open a newline delimited text file and do the following
manipulations: