variables

Can I use variables in HTML?

故事扮演 提交于 2020-01-15 11:22:26
问题 I have 5 .html pages. I have the same navigation for each page. Is there any way I can set a variable somewhere that contains my navigation code, and then reference that variable in each of my documents? I want to do this because if I ever want to edit my navigation, I can just go back and edit 1 source (the variable), as opposed to editing from each document. 回答1: Pure HTML (without JavaScript) cannot load in another page on it's own. However, you can use PHP, SHTML, or JavaScript to obtain

Using variables inside a bash heredoc

不羁岁月 提交于 2020-01-15 11:22:08
问题 I'm trying to interpolate variables inside of a bash heredoc: var=$1 sudo tee "/path/to/outfile" > /dev/null << "EOF" Some text that contains my $var EOF This isn't working as I'd expect ( $var is treated literally, not expanded). I need to use sudo tee because creating the file requires sudo. Doing something like: sudo cat > /path/to/outfile <<EOT my text... EOT Doesn't work, because >outfile opens the file in the current shell, which is not using sudo. 回答1: In answer to your first question,

Having trouble keeping all variables after removing duplicates from a dataset

不羁岁月 提交于 2020-01-15 06:49:12
问题 So, I imported a dataset with 178 observations and 8 variables. Then end goal was to eliminate all observations that were the same across three of those variables (2, 5, and 6). This proved quite easy using the unique command. mav2 <- unique(mav[,c(2,5,6)]) The resulting mav2 dataframe produced 55 observations, getting rid of all the duplicates! Unfortunately, it also got rid of the other five variables that I did not use in the unique command (1,3,4,7, and 8). I initially tried adding the

What's wrong with this youtube-dl automatic script?

你离开我真会死。 提交于 2020-01-15 05:57:50
问题 first of all, I'm quite new with bash scripting and I'm just starting to learn, evidently there's something wrong with this script, but I don't know what it is... I created a bash script to automate downloading videos with youtube-dl: #!/bin/bash echo url: read url export url youtube-dl -f 'bestvideo[height<=360]+worstaudio/worst[height<=360]' $url The idea is that I type in the command line the name of the script, e.g.: "360" and it will ask for a url (e.g.: a Youtube video), I paste it and

getting php variable from an object in which one of its properties has $ sign

天涯浪子 提交于 2020-01-15 01:57:08
问题 so I acquired a json object from an API and json decoded it... but then the returned object is of the following: stdClass Object ( [id] => stdClass Object ( [$t] => some string ) ) And as you can see there is a property with a $ sign in it but when I do $object->id->$t <--that returns error since it thinks $t is a variable how would I go about fetching that variable with $ sign? 回答1: Encapsulate it as a single-quoted string: echo $object->id->{'$t'}; Note that you cannot use double quotes for

Assign file names to a variable in shell

给你一囗甜甜゛ 提交于 2020-01-14 22:54:23
问题 I'm trying to write a script that does something a bit more sophisticated than what I'm going to show you, but I know that the problem is in this part. I want each name of a list of files in a directory to be assigned to a variable (the same variable, one at a time) through a for loop, then do something inside of the loop with this, see what mean: for thing in $(ls $1); do file $thing; done Edit: let's say this scrypt is called Scrypt and I have a folder named Folder, and it has 3 files

Find specific variables inside a function and return them sorted

亡梦爱人 提交于 2020-01-14 19:17:29
问题 first of all, thank you for your help in forward. I'm using Python and I'm trying to search a .py file for all of its functions starting with the name "test_" and all of the variables included. The variables I search for are formatted like this: "var["blabla"]". So here I have an example: def test_123: init = var["blabla1"] init2 = var["blabla2"] *somecode* def test_456: init3 = var["blabla3"] init4 = var["blabla4"] *somecode* What I already wrote is a script, that returns all my functions

Set Input Value to Javascript Variable

a 夏天 提交于 2020-01-14 09:44:21
问题 Let's say I have a variable called x in javascript. How can I set the value of a text input (HTML) to that variable? For example: The value of the input will now be Swag <input type="text" value="Swag" /> But if I want the value to be a javascript variable? How do I do? Something like this? (I am just guessing, trying to make my point clear) <input type="text" value="variable.x" /> 回答1: You can set it in your javascript code like: <input id="myInput" type="text" value="Swag" /> <script> var

variable-scope in R functions

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-14 07:58:30
问题 I'd like to specify functions in a flexible way. How can I make sure that the environment of a given function does not change when I create another function just after it. To illustrate, this works properly: make.fn2 <- function(a, b) { fn2 <- function(x) { return( x + a + b ) } return( fn2 ) } a <- 2; b <- 3 fn2.1 <- make.fn2(a, b) fn2.1(3) # 8 fn2.1(4) # 9 a <- 4 fn2.2 <- make.fn2(a, b) fn2.2(3) # 10 fn2.1(3) # 8 This does not make.fn2 <- function(a, b) { fn2 <- function(x) { return( x + a

How can I clear class variables between rspec tests in ruby

戏子无情 提交于 2020-01-14 07:06:07
问题 I have the following class: I want to ensure the class url is only set once for all instances. class DataFactory @@url = nil def initialize() begin if @@url.nil? Rails.logger.debug "Setting url" @@url = MY_CONFIG["my value"] end rescue Exception raise DataFactoryError, "Error!" end end end I have two tests: it "should log a message" do APP_CONFIG = {"my value" => "test"} Rails.stub(:logger).and_return(logger_mock) logger_mock.should_receive(:debug).with "Setting url" t = DataFactory.new t =