This file contains 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
#newton-raphson for sq root | |
def newton(square): | |
guess = square/2.0 | |
attempts = 0 | |
# f(x) = x**2 - square | |
# then f'(x) = 2x | |
while abs(guess*guess) - square >= .001: | |
# print guess | |
attempts+=1 | |
guess = guess - ((guess**2 - square)/(2*guess)) |
This file contains 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
public class QuickFindWeighted | |
{ | |
private int[] arr; //the nodes | |
private int[] size; //the levels on the graph | |
public QuickFindWeighted(int n) { | |
arr = new int[n]; | |
size = new int[n]; | |
for (int i=0;i<n;i++) { | |
arr[i] = i; |
This file contains 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
mongod --replSet rs1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --fork | |
mongod --replSet rs2 --logpath "2.log" --dbpath /data/rs1 --port 27018 --fork | |
mongod --replSet rs3 --logpath "3.log" --dbpath /data/rs1 --port 27019 --fork | |
This file contains 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
def index | |
@products = Product.includes(:user).all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render json: @products } | |
format.xml { render xml: @products } | |
end | |
end | |
This file contains 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
<!-- Enable annotation scanning. --> | |
<context:component-scan base-package="com.matthewjkim.controllers" /> | |
<!-- Map objects to XML. --> | |
<bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller" /> | |
<bean id="xmlMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"> | |
<constructor-arg ref="xstreamMarshaller" /> | |
</bean> | |
<bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" /> | |
<!-- Bind the return value of the Rest service to the ResponseBody. --> | |
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> |
This file contains 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
options = [{property: “name", variants: [A,B,C]}, {property: “size", variants: [1,2,3]} ,{property: “color", variants: [Blue,Green]}] | |
3x3x2 = 18 combinations | |
A-1-Blue | |
A-1-Green | |
A-2-Blue | |
A-2-Green |
This file contains 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
document.mynumberlist[0] = 2; | |
document.save(); |
This file contains 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
document.mynumberlist[0] = 2; | |
document.markModified('mynumberlist'); //notify mongoose of the change | |
document.save(); |
This file contains 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
document.mynumberlist.set(0, 2); | |
document.save(); |
This file contains 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
// will not save updated date | |
doc.eventDate.setDay(10); | |
doc.save(); | |
// will save updated date | |
doc.eventDate.setDay(10); | |
doc.markModified('eventDate'); | |
doc.save(); |
OlderNewer