Home » Web Development » Page 4

I'm displaying question by categories and each question has its own
number. I made it like this(index.html.erb):



<% @categories.each do |category| %>
<div id=<%= "box#{category.id}" -%>>
<h1><%= category.name %></h1>
<% category.questions.each_with_index do |question, i|
%>
<ul class="question-list" style="display: inline;">
<li><%= link_to (i + 1), show_path
%></li>
</ul>
<% end %>
</div>
<% end %>


And when I click on question number I would like to show it like
this(show.html.erb):



<div class="question-wrapper">
<h1><%= @category.name %></h1>
<div class="image left-align">
<%= question_image_tag(question, :large) %>
</div>
<div class="question-text right-align">
<%= @question.question_name %>
</div>
<p><%= @question.answer %></p>
</div>


This is my controller:



def index
@categories = Category.all
@questions = Question.all
end

def show
@categories = Category.all
@questions = Question.all
end


Now, I'm getting undefined method `name' for nil:NilClass (also
throws error for all methods in show.html.erb) and I can't resolve
it.



Question: What should I do to resolve undefined method
`name' for nil:NilClass?


I am sending the json request code give the error Is there any
way how
to send the json request with authentication.this Code give the
Error
in filenotfound " rel="nofollow">http://api.seatseller.travel/blockTicket"

//st =
json object




       StringBuilder sb = new StringBuilder();  
JSONObject jsonParam = st;//JSON
HttpURLConnection request=null;
OAuthConsumer consumer = new
DefaultOAuthConsumer("tOzL5hTkSz9KiA2RIAECW4g7Uq","cj8HLPmBKnRAsffLe5qpQIZ9Y");
consumer.setTokenWithSecret(null, null); //i pass token as
access token as a null as my server dont need it.

URL url = new URL("http://api.seatseller.travel/blockTicket");
request = (HttpURLConnection) url.openConnection();
request.setDoOutput(true);
request.setRequestMethod("GET");
request.setUseCaches(false);
request.setConnectTimeout(10000);
request.setReadTimeout(10000);
request.setRequestProperty("Content-Type","application/json");


request.setRequestProperty("Host", "android.schoolportal.gr");


consumer.sign(request);
request.connect();
OutputStreamWriter out = new
OutputStreamWriter(request.getOutputStream());
out.write(jsonParam.toString());
out.close();
int HttpResult =request.getResponseCode();
if(HttpResult ==HttpURLConnection.HTTP_OK){
BufferedReader br = new BufferedReader(new
InputStreamReader(
request.getInputStream(),"utf-8"));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + "
");
}
br.close();

System.out.println(""+sb.toString());

}else{
System.out.println(request.getResponseMessage());
}
} catch (MalformedURLException e) {

e.printStackTrace();
}
catch (IOException e) {

e.printStackTrace();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

I have the following database structure.



src="http://i.imgur.com/19rZ0W1.png" alt="structure">



Sorry for the horrible MS Paint Work



I am using .NET Framework 4.6.1 Web API Controller using Entity
Framework.



My API Controller handles a post request that receives a structure
similar to:



{  "countryCode": "CA", "languageCode": "EN ","partTypes":
"Brakes", "partComponents": "Relay" }


^^ Above request should find Part ID = 1 , and I want to select
Part Request URL



{ "countryCode": "US","languageCode": "EN ","partTypes": "
Brakes , Clutch", "partComponents": "Relay"}


^^ Above request should find Part ID = 1 & 2 , and I want to
select Part Request URL for both.



“Clutch, Resistor, EN, US” Should find Part ID = 2 etc.



My Question is how am I able to use LINQ to SQL or
<IQueryable> to return the part ID for whatever
post request is captured by the controller.
The current code I have been working on so far looks similar to
this:



Inside API Controller:



public string Post(PostProfile postProfile) 
string[] partURLArray;
{
using (var context = new context())
{partURLArray = context.ViewName
.Where(fields = >
field.CountryCode.Contains(postProfile.countryCode)
.Where(fields =>
fields.LanguageCode.Contains(postProfile.languageCode)
.Select(fields => fields.PartRequestURL).ToArray();
}
foreach
(var part in partURLArray)
{
//do some stuff
}
return partString
}


Post Profile Model Class:



    public string countryCode { get; set; }
public string languageCode { get; set; }
public string[] partType { get; set; }
public string[] partComponents { get; set; }

I have following method



static void setName(const char* str, char buf[16])
{
int sz = MIN(strlen(str), 16);
for (int i = 0; i < sz; i++) buf[i] = str[i];
buf[sz] = 0;
}


int main()
{
const char* string1 = "I am getting bug for this long string
greater than 16 lenght);
char mbuf[16];
setName(string,mybuf)
// if I use buf in my code it is leading to spurious characters
since length is greater than 16 .


Please let me know what is the correct way to code above if the
restriction for buf length is 16 in method static void setName(const
char* str, char buf[16])

I have a lot of elements in my XAML code that i need to switch
between visible and collapsed in my main code...



I have tried to create a parent of type StackPanel for
all those elements. But now it messes up all the child element
positions (it scatters them all over the place).



Is there any way to set that the parent does not control the
position of the child and only controls the Visibility property... Or
is there any other type of element used for parenting and grouping
?

The variable $role_id1 is not being fetched in $role_id in
$_POST['add sub menu'].
I want to store $role_id1 in $role_id and insert into database.Afer
i click the submit button the role_id1 is fetching the parent menu but
after i click add sub menu the role_id is storing 0 at backend.But i
want it to store the vale of role_id1 which is being fetched after i
click submit.Suggest any solution if possible.



  <?php

$dbcon = new MySQLi("localhost","root","","menu");
if(isset($_POST['add_main_menu']))
{
$menu_name = $_POST['menu_name'];
$parent_id = 0;
$role_id = $_POST['role_id'];
$menu_link = $_POST['mn_link'];
$sql=$dbcon->query("INSERT INTO menu
VALUES('','$menu_name','$parent_id','$role_id','$menu_link')");
}
if(isset($_POST['add_sub_menu']))
{
$parent_id = $_POST['parent'];
$name = $_POST['sub_menu_name'];

$role_id = $role_id1;
$menu_link = $_POST['sub_menu_link'];

$sql=$dbcon->query("INSERT INTO menu
VALUES('','$name','$parent_id','$role_id','$menu_link')");
}

?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"
/>
<title>Dynamic Dropdown Menu</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all"
/>
</head>
<body>
<div id="head">
<div class="wrap"><br />
<h1><a href="index.php">Back to menu</a></h1>
</div>
</div>
<center>
<pre>
<form method="post">
<input type="text" placeholder="menu name :" name="menu name"
/><br />

<input type="text" placeholder="role id :" name="role_id"
/><br />
<input type="text" placeholder="menu link :" name="mn_link"
/><br />
<button type="submit" name="add_main_menu">Add main
menu</button>
</form>
</pre>
<br />
<pre>
<form method="post">
<select name="role_id">
<option selected="selected">select role id</option>

<?php
$res=$dbcon->query("SELECT distinct role_id FROM menu");
while($row=$res->fetch_array())
{
?>
<option value="<?php echo $row['role_id'];
?>"><?php echo $row['role_id']; ?></option>
<?php
}
?>
</select><br />
<input type="submit" value="submit" name="submit">

<?php if(isset($_POST['submit']))
{
?>
<select name="parent">
<option selected="selected">select parent menu</option>
<?php
$role_id1 = $_POST['role_id'];

$res=$dbcon->query("SELECT * FROM menu where role_id= $role_id1 AND
parent_id=0 ");
while($row=$res->fetch_array())
{
?>
<option value="<?php echo $row['id']; ?>"><?php
echo $row['name']
;

?></option>
<?php


}
}



?>
</select><br />
<input type="text" placeholder="menu name :"
name="sub_menu_name" /><br />
<input type="text" placeholder="menu link :"
name="sub_menu_link" /><br />
<button type="submit" name="add_sub_menu">Add sub
menu</button>
</form>
</pre>
<a href="index.php">back to main page</a>
</center>

</body>
</html>

I have a spark streaming job that read tweets stream from gnip and
write it to Kafak.



Spark and kafka are running on the same cluster.



My cluster consists of 5 nodes. Kafka-b01 ... Kafka-b05



Spark master is running on Kafak-b05.



Here is how we submit the spark job



nohup sh $SPZRK_HOME/bin/spark-submit
--total-executor-cores 5 --class
org.css.java.gnipStreaming.GnipSparkStreamer --master
spark://kafka-b05:7077 GnipStreamContainer.jar powertrack
kafka-b01.css.org,kafka-b02.css.org,kafka-b03.css.org,kafka-b04.css.org,kafka-b05.css.org
gnip_live_stream 2 &



After about 1 hour the spark job get killed



The logs in the nohub file shows the following exception



org.apache.spark.storage.BlockFetchException: Failed to
fetch block from 2 locations. Most recent failure cause:
at
org.apache.spark.storage.BlockManager$$anonfun$doGetRemote$2.apply(BlockManager.scala:595)

at
org.apache.spark.storage.BlockManager$$anonfun$doGetRemote$2.apply(BlockManager.scala:585)

at
scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)

at
scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
at
org.apache.spark.storage.BlockManager.doGetRemote(BlockManager.scala:585)

at
org.apache.spark.storage.BlockManager.getRemote(BlockManager.scala:570)

at
org.apache.spark.storage.BlockManager.get(BlockManager.scala:630)
at org.apache.spark.rdd.BlockRDD.compute(BlockRDD.scala:48)
at
org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:306)
at org.apache.spark.rdd.RDD.iterator(RDD.scala:270)
at
org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
at org.apache.spark.scheduler.Task.run(Task.scala:89)
at
org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:745)
Caused by: io.netty.channel.ChannelException: Unable to create Channel
from class class io.netty.channel.socket.nio.NioSocketChannel
at
io.netty.bootstrap.AbstractBootstrap$BootstrapChannelFactory.newChannel(AbstractBootstrap.java:455)

at
io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:306)

at io.netty.bootstrap.Bootstrap.doConnect(Bootstrap.java:134)
at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:116)
at
org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:211)

at
org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:167)

at
org.apache.spark.network.netty.NettyBlockTransferService$$anon$1.createAndStart(NettyBlockTransferService.scala:90)

at
org.apache.spark.network.shuffle.RetryingBlockFetcher.fetchAllOutstanding(RetryingBlockFetcher.java:140)

at
org.apache.spark.network.shuffle.RetryingBlockFetcher.start(RetryingBlockFetcher.java:120)

at
org.apache.spark.network.netty.NettyBlockTransferService.fetchBlocks(NettyBlockTransferService.scala:99)

at
org.apache.spark.network.BlockTransferService.fetchBlockSync(BlockTransferService.scala:89)

at
org.apache.spark.storage.BlockManager$$anonfun$doGetRemote$2.apply(BlockManager.scala:588)

... 15 more
Caused by: io.netty.channel.ChannelException: Failed to open a socket.

at
io.netty.channel.socket.nio.NioSocketChannel.newSocket(NioSocketChannel.java:62)

at
io.netty.channel.socket.nio.NioSocketChannel.<init>(NioSocketChannel.java:72)

at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at
io.netty.bootstrap.AbstractBootstrap$BootstrapChannelFactory.newChannel(AbstractBootstrap.java:453)

... 26 more
Caused by: java.net.SocketException: Too many open files
at sun.nio.ch.Net.socket0(Native Method)
at sun.nio.ch.Net.socket(Net.java:411)
at sun.nio.ch.Net.socket(Net.java:404)
at
sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:105)
at
sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)

at
io.netty.channel.socket.nio.NioSocketChannel.newSocket(NioSocketChannel.java:60)

... 33 more


I have increased the maximum number of open files to 3275782 (the
old number was almost half of this number) but I am still facing the
same issue.



When I checked the stderr logs of the workers from
spark web interface I found another exception.



java.nio.channels.ClosedChannelException 
at
kafka.network.BlockingChannel.send(BlockingChannel.scala:110)
at
kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:75)
at
kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:74)

at kafka.producer.SyncProducer.send(SyncProducer.scala:119)
at
kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:59)
at
kafka.producer.BrokerPartitionInfo.updateInfo(BrokerPartitionInfo.scala:82)

at
kafka.producer.BrokerPartitionInfo.getBrokerPartitionInfo(BrokerPartitionInfo.scala:49)

at
kafka.producer.async.DefaultEventHandler.kafka$producer$async$DefaultEventHandler$$getPartitionListForTopic(DefaultEventHandler.scala:188)

at
kafka.producer.async.DefaultEventHandler$$anonfun$partitionAndCollate$1.apply(DefaultEventHandler.scala:152)

at
kafka.producer.async.DefaultEventHandler$$anonfun$partitionAndCollate$1.apply(DefaultEventHandler.scala:151)

at
scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)

at
scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
at
kafka.producer.async.DefaultEventHandler.partitionAndCollate(DefaultEventHandler.scala:151)

at
kafka.producer.async.DefaultEventHandler.dispatchSerializedData(DefaultEventHandler.scala:96)

at
kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:73)

at kafka.producer.Producer.send(Producer.scala:77)
at kafka.javaapi.producer.Producer.send(Producer.scala:33)
at
org.css.java.gnipStreaming.GnipSparkStreamer$1$1.call(GnipSparkStreamer.java:59)

at
org.css.java.gnipStreaming.GnipSparkStreamer$1$1.call(GnipSparkStreamer.java:51)

at
org.apache.spark.api.java.JavaRDDLike$$anonfun$foreachPartition$1.apply(JavaRDDLike.scala:225)

at
org.apache.spark.api.java.JavaRDDLike$$anonfun$foreachPartition$1.apply(JavaRDDLike.scala:225)

at
org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$33.apply(RDD.scala:920)

at
org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$33.apply(RDD.scala:920)

at
org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)

at
org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)

at
org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
at org.apache.spark.scheduler.Task.run(Task.scala:89)
at
org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:745)


The second exception (as it seems) is related to Kafka not spark.



What do you think the problem is?



EDIT



based on a comment from Yuval Itzchakov Here is the code of the
streamer



The main class rel="nofollow">http://pastebin.com/EcbnQQ3a



The customer receiver class rel="nofollow">http://pastebin.com/3UFPktKR

I want to link an external java script file with my freemarker
template
I used the normal <script type="text/javascript"
src="test.js"/>
but it didn't work , it works only when I
use include which is not what I want .
I want to use the js file as external one.

I am learning generator in python,here the functions:



import math
def is_primes(number):
if number > 1:
if number == 2:
return True
if number % 2 == 0:
return False
for current in range(3, int(math.sqrt(number) + 1), 2):
if number % current == 0:
return False
return True
return False


def get_primes1(number):
while True:
if is_primes(number):
yield number
number +=1

def get_primes2(number):
while True:
if is_primes(number):
number=yield number
number +=1


when using the send function:



a=get_primes1(2)
b=get_primes2(2)
a.send(None)#return 2
b.send(None)#return 2
a.send(1)#return 3,the parameter in send() looks useless.
b.send(1)#return 1,normal


when using the "a.send(1)" and "b.send(1)" repeatly,a.send(1)
return the bigger value but b.send(1) still return the same value.why
there is difference?



i check the meaning of send function:




Resumes the execution and ``sends'' a value into the generator
function. The value argument becomes the result of the current
yieldexpression. The send() method returns the next value yielded by
the generator, or raises StopIteration if the generator exits without
yielding another value. When send() is called to start the generator,
it must be called with None as the argument, because there is no yield
expression that could receieve the value.


My app is creating a bunch of pictures and I want to open the
folder with the user's gallery app so the user can watch, print, share
them, or do whatever he likes.



The standard solution:



Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(folder);
intent.setDataAndType(uri,"*/*");
startActivity(Intent.createChooser(intent, "Open folder"));


Opens the folder in the phone's gallery, but if I click on an
image, the galery closes instead of displaying the picture and staying
alive.



My closest solution



Intent gallery = new Intent(Intent.ACTION_MAIN, null);
gallery.addCategory(Intent.CATEGORY_APP_GALLERY);
Intent chooser = Intent.createChooser(gallery, "Gallery");
startActivity(chooser);


Opens the full blown phones gallery app with all its abilities, but
only on its root folder.



How can I open the full blown gallery app on a specific folder so
that it doesn't close when an image is selected? A nice bonus would be
the ability to open the pictures in the gallery as if the user had
activated the slide show already.


- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow