w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
C# read from text file and store in variables
I would need to see more of your input data to determine the most reliable method. But one approach would be to split each address into words. You can then loop through the words and find each word that contains only digits. This will be your street number. You could look after the street number and look for S, So, or South but as your example illustrates, there might be no such indicator. Also, you haven't provided what you want to happen if more than one number is found. As far as removing the quotes, just remove the first and last characters. I'd recommend checking that they are in fact quotes before removing them.

Categories : C#

Batch File Store Line Variables And Sum Them Up
try this: @echo off &setlocal enabledelayedexpansion set count=0 (for /f "tokens=3" %%i in ('findstr "Count" Count.txt') do ( set /a count+=%%i echo !count! ))> finalcount.txt

Categories : Windows

How can I access ruby/rails app variables through an external JS file
You can make another controller which would search the user's number via the cookie (or any other value that relates to the user's number) then get it via ajax. Note: Untested Code Controller (configure your routes as well): class UsersController < ApplicationController def get_number @cookie = params[:cookie] @user = User.where(cookie: @cookie).first render json: @user.to_json end end Then in your application.js $.get("<your controller route>",{cookie: value},function(data){ var testswap = function(){ var swap = document.getElementById("test").textContent; document.getElementById("test").textContent = data.number; } });

Categories : Javascript

prestashop (php / SESSION variables ) how to store variables from a form and use them in if / else commands
In prestashop 1.5, global are deprecated. To set something in the cookie : In a controller : $this->context->cookie->__set($key,$value); Other file : $context = Context::getContext(); $context->cookie->__set($key,$value); You can access to your value with : In a controller $this->context->cookie->key Other file : $context = Context::getContext(); $context->cookie->key; Prestashop doesn't use the $_SESSSION, so you can't access to $smarty.session.key You have to assign your variable to smarty In a controller : $this->context->smarty->assign(array('key' => $this->context->cookie->key)); Other file : $context = Context::getContext(); $context->smarty->assign(array('key' => $context->cookie->key));

Categories : PHP

Is it possible to solve for an input value of a hash in ruby if all other variables and output are known? (In ruby)
If v2 and v3 are integers. You could theoretically attempt to brute force it by just running through numbers and finding when the hashes match. Then subtract v2 and v3. If your set of possible numbers is all real numbers though, this would be extremely hard. And you'd be better off running it on multiple machines with greatly varying rotating subsections of real numbers. That's you're best bet. And that's assuming the values are integers.

Categories : Ruby On Rails

Changing object variables in an array of instance variables in Ruby
class Cell attr_accessor :values @arrs = [] #Creates a "class instance variable" class <<self #Creates an accessor for the "class instance variable" attr_reader :arrs end def initialize(values) @values = values self.class.arrs << @values #Add the @values array to the "class instance variable" end end test_array = [1, 2, 3] @cells = test_array.map do |num| #Create the cells Cell.new(test_array.dup) end p @cells --output:-- [#<Cell:0x0000010085ffd8 @values=[1, 2, 3]>, #<Cell:0x0000010085ff88 @values=[1, 2, 3]>, #<Cell:0x0000010085ff60 @values=[1, 2, 3]>] @cells.each_with_index do |cell, i| #Change the last value of each cell's @values array cell.values[-1] = i end p Cell.arrs #Show all the @values arrays of

Categories : Ruby

How to store post variables value
The comments are correct. Use: // Start the session session_start(); // Save variables into session $_SESSION['somevalue'] = $_POST['value']; Then when any page calls session_start it will have access to $_SESSION['somevalue'] Also, you are wide open for SQL injection. Sanitize your values to ensure no one can put arbitrary sql code into the string. if you are using mysqli it should as simple as this: // After connecting to the DB $_POST['somevalue' = $mysqli->real_escape_string($_POST['somevalue']); Then be sure to hardcode quotes around string values like you are doing. If you want to be safer you can use prepared statement instead. Hope this helps.

Categories : PHP

How to Use Hashes to Store methods in Ruby?
Hashes can not store methods. Methods aren't objects, but can be converted to Procs. Method definitions return nil. However, you can store a Proc or a lambda. You can also store the return of a method. Here is an example of how you can store a Proc to a Hash that was derived from a method. >> def hello(name) >> "Hello #{name}!" >> end => nil >> my_stored_methods = {:hello => method(:hello).to_proc} => {:hello=>#<Proc:0x816f604 (lambda)>} >> my_stored_methods[:hello].call("World") => "Hello World!" Do not let the stroop effect of me calling the hash "my_stored_methods" lead you to believe that there is actually a real method stored there. It is lambda (a specialized Proc) stored in the hash, and used as appropriate. Indeed, ha

Categories : Ruby

How to save variables to a file so that those variables are loaded the next time the site runs?
You can use local storage or even cookies. local storage is your best bet, although it doesn't work in older browsers. cookies are (more) limited in their capacity (4KB vs 5MB for local storage) and also are sent to the server with each request, which may not be what you want. Alternatively, you can store the state on your server (you'll need some server side scripting as well), and only store a user/gamer id in a cookie.

Categories : Javascript

Threadsafety of Ruby variables?
Basically, you are right, inside a single request you can safely use any local variables unless you are spawning any threads yourself. Also if you use server like Unicorn that uses workers (separate process) for processing requests you are "threadsafe" as each process lives in its own memory space and only one request is being processed at a time. Problems may occur if you have a threaded server like Puma that can process multiple requests in parallel inside a single Ruby process. This is where race conditions may start and if you have a code like: class User delf.self.current_user @@current_user end end User.current_user.destroy The @@current_user variable may get changed by parallel process and you can accidentally destroy wrong user.

Categories : Ruby On Rails

Using global variables ruby
You're correct. You need to make the variable global by prefixing it with $. Ex: $tmp_dir = '/path/to/tmp/dir' Rather than do that, you could also make it an instance variable, or you could refactor to make it a class. I would recommend doing what Riley Lark said.

Categories : Ruby

ruby - how to assign a value to 2 variables at once
You're currently doing it the right way... Two = isn't clumsy. It evaluates from right to left as it should... >> a = b = :c => :c >> a => :c >> b => :c But if you really want to avoid them, you could repeat yourself and use this, for instance: >> a, b = :c, :c => [:c, :c] >> a => :c >> b => :c

Categories : Ruby

Writing an App with jQuery - how to store variables?
You are reloading the JavaScript, resetting the variables. Some solutions: You should use ajax to change your content. Use cookies. (Not recommended) Store the variables as parameters in the url. (Not pretty)

Categories : Javascript

How does JavaScript store DOM elements in variables?
foo becomes the function. So you wouldn't be able to add foo to bar because that doesn't make sense. It would be like trying to do: document.form[0].getElementsByName('input') document.form[1].getElementsByName('input'); You could have multiple elements in a single array. I'd find that to be the simplest way to reach your solution.

Categories : Javascript

Store variables in ELF section and iterate them later
The manual's example is pretty decent. I've minimized it a bit for the this answer: char stack[10000] __attribute__ ((section ("STACK"))) = { 0 }; main() { /* Initialize stack pointer */ init_sp (stack + sizeof (stack)); } Notice how the code that references stack doesn't have to "iterate over a memory segment", it just deals with stack, and the compiler/linker will make sure that access is at the proper place depending on where the section ends up. Typically you don't have to know or do anything in particular to access the variables; the fact that they have been put in a specific segment is something that is below the abstraction level of the language, in which all variables that are in scope are generally accessed by name just as usual.

Categories : C

Trying to store NSString into UITableViewCell with the given variables
If you're trying to populate a UITableView you should implement the the following two methods: - (UITableViewCell *)tableview:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section Then in the first method (tableView: cellForIndexPath:) you'd create a UITableViewCell and populate its properties with your data. Make sure you set your ViewController to be the delegate and datasource for the UITableView.

Categories : IOS

Using ruby variables as html code
always remember to use raw or html_safe for html output in rails because rails by default auto-escapes html content for protecting against XSS attacks. for more see When to use raw() and when to use .html_safe

Categories : HTML

Ruby: Assigning Variables in Groups
You can do as below : variable1 = variable2 = variable3 = 0 Read This question :- is it right to assigning multiple variable like this a = b = c = d = 5 in ruby? So generic approach is: variable1, variable2, variable3 = [0] * 3

Categories : Ruby

Variables not recognized within Rescue in Ruby
The way you put it, it should work, for example: irb(main):001:0> begin irb(main):002:1* x = 1 irb(main):003:1> x / 0 irb(main):004:1> rescue Exception => e irb(main):005:1> p x irb(main):006:1> end 1 => 1 So it looks like the exception is thrown before your variables are defined.

Categories : Ruby

ruby style and instance variables
Accessing the attribute through the getter has the advantage of providing encapsulation. The use of an instance variable to store the value is an implementation detail in some respects. Whether that's appropriate is, of course, situational. I don't recall reading anything explicit this style issue, however. Found http://programmers.stackexchange.com/questions/181567/should-the-methods-of-a-class-call-its-own-getters-and-setters, which discusses the issue from a language-independent point of view. Also found https://www.ruby-forum.com/topic/141107, which is ruby-specific, although it doesn't break any new ground, let alone imply a Ruby standard. Update: Just came across the following statement on page 24 of http://www.amazon.com/Practical-Object-Oriented-Design-Ruby-Addison-Wesley/dp/0321

Categories : Ruby

Best way to store variables in a function that will be used multiple times (c++)
Usually you would pass in all the input data the algorithm needs as input parameters, and return all the useful output data the algorithm creats as a return type. You could create a separate C++ struct or class if you need to bundle a few pieces of information together. For data structures used internally by the algorithm - you would usually declare them only in the .cpp file, not the .h file. So, the user will not have any access / visibility of the internals (which is useful if you want to change how it works later). So, the header file should just have the function declaration - with input arguments and output return type. All the algorithm code goes into the .cpp file, which includes the .h file. The header file is the 'interface' and the cpp file is the 'implementation', which w

Categories : C++

How to store variables in all pages requestScopes within Spring
I think you have at least two possible options for this: Using an MVC Interceptor. With an interceptor you can perform common operations for all requests. You can extend HandlerInterceptorAdapter and add common model data in postHandle Using the @ModelAttribute annotation within an Controller. You can use this to add common data for all request mappings within a controller. You can also use an @ControllerAdvice (with @ModelAttribute annotated methods inside) if you want provide model data to all controllers. The section Using @ModelAttribute on a method should provide some additional information for this.

Categories : Spring

How can you store user variables accessible by a rubygem?
For command line gems, I've seen lots of them using a yml file to store user preference data, usually a dot file under root or usage directory. That's a preferred way IMO and I like that. You need also set default preference in gem in case there is no user's settings.

Categories : Ruby

Does C# compiler convert and store static variables?
The constant Int32.MaxValue is stored at compile time, and in fact your code would be converted to Convert.ToDouble(0x7FFFFFFF) at compile time. The equivalent IL is: ldc.i4 FF FF FF 7F call System.Convert.ToDouble This value is also saved so it can be retrieved at run-time through reflection. However, Convert.ToDouble is a function that is only evaluated at run-time. As minitech suggests, (double)Int32.MaxValue is evaluated at compile-time. The equivalent IL is: ldc.r8 00 00 C0 FF FF FF DF 41

Categories : C#

Jquery variables only store limited data
64K can actually go by really quickly, especially if you have a table, and double-especially with base64 embedded images. Try changing to a LONGTEXT. If that works, then that was your problem.

Categories : Jquery

WebAPI store variables for specific user
You need some memory cache. Have a look at: MemoryCache Class Store the DirectoryEntry object in the cache with the path as key.

Categories : C#

Perl: Is is possible for a Hash to store mixed variables?
Yes, it is possible, and most easily done with lexical variables: sub mysub { my %hash1; my %hash2; my %hash3; my @array1; my @array2; my @array3; ... my %all = ( hash1 => \%hash1, hash2 => \%hash2, array1 => @array1, # etc ); return \%all; } You return a single scalar value which is a hash reference, containing all the data.

Categories : Arrays

How can store javascript variable to php session variables?
There are actually only a few options to pass information from javascript (or the browser that is) to php: Using an Ajax request. This can be both a GET or a POST request (variables in php residing in the $_GET or $_POST array respectively Using a form: add the data you want to send to a oldschool html form and post it. By magic: put a toothbrush against your head, turn around 7 times and murmur some non-existent words. It might help.

Categories : PHP

What's a good way to store unchanging variables in a C# project?
There are a lot of different ways to do this. You could store the data in a static readonly dictionary. public static readonly Dictionary<int, int> MY_DICTIONARY; And place this inside a static class available throughout your project. You could also store data in the Properties settings.settings file. Generally, in my C# code I try to avoid global data and instead pass information when it is needed. This allows for code that is more easily tested.

Categories : C#

Is it ok to place all JS / jQuery variables at top of file? Global variables?
Global variables are scoped to the program, so if you pull in other javascript that also uses the same global variable names you will almost certainly encounter bugs. If you're writing something fairly small there's certainly nothing (technically) wrong with declaring all of your variables as global, but if you're writing something that's going to grow it might be to your benefit to use some form of module pattern to provide another level of scope to your variables and minimize the use of Globals. With a module pattern you can usually reduce your global variables down to the Module namespace, with what would normally be globals, scoped only up to the module.

Categories : File

How to store 4-byte character in MySQL 5.5 using ruby (mysql2 gem)
Prerequisite: MySQL >= 5.5.3 Character set named utf8 (or utf8mb3) uses a maximum of three bytes per character and contains only BMP characters. In order to have a maximum of four bytes per character, you need to: switch charset/collation of all your tables/columns to utf8mb4 edit your config/database.yml to change the encoding: utf8 lines to encoding: utf8mb4 (and a recent mysql2 gem?)

Categories : Mysql

In Ruby, why do you need to initialize child class variables?
Why so? Okay Let me tell you then this way : class Foo @foo_count = 0 end class Bar < Foo;end Bar.instance_variables # => [] Foo.instance_variables # => [:@foo_count] @foo_count class instance variable of the class Foo. Whenever you will be creating a subclass like a Bar, from a super class like Foo, don't think that class instance variable will be inherited to the class Bar. Now see - class Foo @foo_count = 0 end class Bar < Foo @foo_count = 10 end Bar.instance_variables # => [:@foo_count] Foo.instance_variables # => [:@foo_count] Now both the object Foo and Bar have their instance variable,having same name @foo_count only,that doesn't mean that they are sharing the same instance variable.Each object has always its own copy of instance variables. Her

Categories : Ruby

Ruby listing only the local variables I defined
a=1 b=2 c=3 local_variables.each{|v| puts v} I guess you mean you might have other variables in your code but you just want some of them in particular. How about putting them into a function and then calling local_variables? It will only print those variables inside the function. If you store the variables in a list you can still do anything you want with them afterwards. unwanted=23 def ada a=1 b=2 c=3 puts local_variables return a,b,c end mygoodlist=ada() #not really necessary p=0 mygoodlist.each{|e| p=p+e} puts p

Categories : Ruby

Freezing variables in Ruby doesn't work
You freeze objects, not variables, i.e. you can't update a frozen object but you can assign a new object to the same variable. Consider this: a = [1,2,3] a.freeze a << 4 # RuntimeError: can't modify frozen Array # `b` and `a` references the same frozen object b = a b << 4 # RuntimeError: can't modify frozen Array # You can replace the object referenced by `a` with an unfrozen one a = [4, 5, 6] a << 7 # => [4, 5, 6, 7] As an aside: it is quite useless to freeze Fixnums, since they are immutable objects.

Categories : Ruby

Methods in ruby dont change variables
The variable is created in the scope of the method and won't be set to the variable that is defined in the global scope. For more info this might be a nice read: http://www.techotopia.com/index.php/Ruby_Variable_Scope You should be able to do this: def load_configurations file_name = nil ARGV.each do |a| file_name = "#{a}" end dest_options = YAML.load_file(file_name) dest_options['dest_name'] end source_connection = load_configurations puts source_connection

Categories : Ruby On Rails

settings env variables on travis and ruby (Gem::LoadError)
You need to install the travis gem: gem install travis or add it to the gemfile of the project you're currently using: gem "travis", "~> 1.5.2"

Categories : Ruby

ruby OR statement executes twice when both variables are true
It's hard to tell from looking at this exactly what could be causing the red dot to appear twice. I'd imagine the containing loop is running twice, but we have no idea what data is in the workout_times. The real problem is that you are setting the values for intensity and @planned_intensity in this view code. You ought to really be doing logic like this in the model or controller. This layer (HTML view templates) is just for presentation. The reason for the separation is so that you don't get hard to pinpoint bugs like this one :) I'd refactor so that the view calls a method on a workout_time object, so that the logic is then in this method. At least then you'll know where to look. You can also unit test this method, whereas testing this view will be awkward. What models do you have ri

Categories : Ruby On Rails

Normally distributed random variables on Ruby on Rails
Thanks for the help in comments. Oli is right, I found the answer in that answer : http://stackoverflow.com/a/8205982/2576033 Using rubystats gem - "a port of the statistics libraries from PHPMath" (pure ruby), you can generate normally distributed variables, easily and in a nice way : gen = Rubystats::NormalDistribution.new(mean, sd) gen.rng # a single random sample gen.rng(100) # 100 random samples

Categories : Ruby On Rails

Getting 2 variables from 1 ajax call in ruby on rails
Ah, This remembers me a piece of code I wrote for you a week ago! You can use JSON to render your Product: #controller def show @product = Product.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render :json => @product.to_json } end end And handle the response from the server like this: $.ajax({ url: "/products/" + selected_product_id, dataType: 'JSON', success: function(data) { var product = JSON.parse(data); $("#description").empty().append(product.item); $("#price").empty().append(product.price); } }); Edit #1: I found this method: jQuery.getJSON : http://api.jquery.com/jQuery.getJSON/

Categories : Ruby On Rails

Ruby: How do I access module local variables?
This has something to do with scope, but I'm not comprehending why this is happening defs create a new scope. In some languages, an inner scope can see the local variables in the surrounding scope--but not in ruby. You could use a constant instead: module MyModule S = "some name" def getName() puts S end end include MyModule getName --output:-- some name But constants can be accessed from anywhere: module MyModule S = "some name" def getName() puts S puts Dog::S end end module Dog S = "hello" end include MyModule getName --output:-- some name hello A more advanced solution involves using a closure. Unlike a def, a block can see the local variables in the surrounding scope, which is known as closing over the variables. Here is an example:

Categories : Ruby



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.