text:
Q: How to properly use mechanize to scrape AJAX sites So I am fairly new to web scraping. There is this site that has a table on it, the values of the table are controlled by Javascript. The values will determine the address of future values that my browser is told to request from the Javascript. These new pages have JSON responses that the script updates the table with in my browser.
So I wanted to build a class with a mechanize method that takes in an url and spits out the body response, the first time a HTML, afterwards, the body response will be JSON, for remaining iterations.
I have something that works but I want to know if I am doing it right or if there is a better way.
class urlMaintain2:
    def __init__(self):

        self.first_append = 0
        self.response = ''

    def pageResponse(self,url):
        import mechanize
        import cookielib

        br = mechanize.Browser()

        #Cookie Jar
        cj = cookielib.LWPCookieJar()
        br.set_cookiejar(cj)

        #Browser options
        br.set_handle_equiv(True)
        br.set_handle_gzip(False)
        br.set_handle_redirect(True)
        br.set_handle_referer(True)
        br.set_handle_robots(False)

        br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

        br.addheaders = [('User-agent','Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16'),
                              ('Accept-Encoding','gzip')]
        if self.first_append == 1:
            br.addheaders.append(['Accept', ' application/json, text/javascript, */*'])
            br.addheaders.append(['Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'])
            br.addheaders.append(['X-Requested-With', 'XMLHttpRequest'])
            br.addheaders.append(['User-agent','Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16'])
            br.addheaders.append(['If-Modified-Since', 'Thu, 1 Jan 1970 00:00:00 GMT'])
            cj.add_cookie_header(br)

        response = br.open(url)
        headers = response.info()

        if headers['Content-Encoding']=='gzip':
            import gzip
            gz = gzip.GzipFile(fileobj=response, mode='rb')
            html = gz.read()
            gz.close()
            headers["Content-type"] = "text/html; charset=utf-8"
            response.set_data(html)
        br.close()
        return response

self.first_append becomes positive after the data has been extracted from the main page html, so the br.addheaders.append don't run the first time through since there is no JSON in the body response, but all the other body responses are JSON. Is this the correct way to do this? Is there a more efficient way?
self.first_append becomes positive after the data has been extracted from the main page html, so the br.addheaders.append don't run the first time through since there is no JSON in the body response, but all the other body responses are JSON. Is this the correct way to do this? Is there a more efficient way? Are there other languages/libraries that do this better?
After a long period of running I get this error message:
File "C:\Users\Donkey\My Documents\Aptana Studio Workspace\UrlMaintain2\src\UrlMaintain2.py", line 55, in pageResponse response = br.open(url)
File "C:\Python27\lib\mechanize_mechanize.py", line 203, in open return self._mech_open(url, data, timeout=timeout)
File "C:\Python27\lib\mechanize_mechanize.py", line 230, in _mech_open response = UserAgentBase.open(self, request, data)
File "C:\Python27\lib\mechanize_opener.py", line 193, in open response = urlopen(self, req, data)
File "C:\Python27\lib\mechanize_urllib2_fork.py", line 344, in _open '_open', req) File "C:\Python27\lib\mechanize_urllib2_fork.py", line 332, in _call_chain result = func(*args)
File "C:\Python27\lib\mechanize_urllib2_fork.py", line 1142, in http_open return self.do_open(httplib.HTTPConnection, req)
File "C:\Python27\lib\mechanize_urllib2_fork.py", line 1118, in do_open raise URLError(err) urllib2.URLError:

It kind of has me lost, not sure why it is being generated but I need to have tons of iterations before I see it.

A: From the mechanize faq "mechanize does not provide any support for JavaScript", it then elaborates on your options (the choices aren't great).
If you've got something working then great but using selenium webdriver is a much better solution for scraping ajax sites than mechanize


text:
Q: how to uninstall gcc-code-assist? I download gcc-code-assist from here, then do "make" and "sudo make install". After I configured my emacs, i found that it can't help me complete large project as my expectation.
I want to uninstall it, however, "make uninstall" report "the uninstall target is not supported in this tree". What can I do if I want to uninstall it?

A: You could remove the settings from your .emacs and continue using gcc-sense/gcc-code-assist as a compiler.  If you need it uninstalled for some reason, you might have to remove the files by hand.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Querying DynamoDB table using Global Secondary Indexes I was trying to query a DynamoDB table using a Lambda function.
My table's partition key is id. I am trying to query it on another key named dipl_idpp. I unstrood that that is not possible.
I found here a solution: I need to create a Global Secondary Index poitning on the column that I want to query on (in my case dipl_idpp).
I did that on Dynamo. But when I execute my function I still have the same problem:
An error occurred (ValidationException) when calling the Query operation: Query condition missed key schema element: id', 'occurred at index 0')"

This is the code I use:
def query_dipl_dynamo(key_table,valeur_query,name_table):
    dynamoDBResource = boto3.resource('dynamodb')
    table = dynamoDBResource.Table(name_table)
    response = table.query(
    KeyConditionExpression=Key(key_table).eq(valeur_query))
    df_fr = pd.DataFrame([response['Items']])
    if len(df_fr.columns) > 0 :
        print("hellooo1")
        df = pd.DataFrame([response['Items'][0]])
        return valeur_query, df["dipl_libelle"].iloc[0]
//
//
df9_tmp["dipl_idpp"] = df8_tmp.apply(lambda x : query_dipl_dynamo("dipl_idpp",x["num_auto"], "ddb-dev-PS_LibreAcces_Dipl_AutExerc")[0], axis=1)

Should I change something else beside creating the index? Too little documentation is available.
Thank you!

A: I just found the solution. When we use Indexes we must provide
an argument namde IndexName who takes the name of the index in Dynamo.
 I had to change my code to:
def query_dipl_dynamo(key_table,valeur_query,name_table):
    dynamoDBResource = boto3.resource('dynamodb')
    table = dynamoDBResource.Table(name_table)
    response = table.query(
    IndexName:"NameOfTheIndexInDynamoDB",
    KeyConditionExpression=Key(key_table).eq(valeur_query))
    df_fr = pd.DataFrame([response['Items']])
    if len(df_fr.columns) > 0 :
        df = pd.DataFrame([response['Items'][0]])
        return valeur_query, df["dipl_libelle"].iloc[0]
//
//
df9_tmp["dipl_idpp"] = df8_tmp.apply(lambda x : query_dipl_dynamo("dipl_idpp",x["num_auto"], "ddb-dev-PS_LibreAcces_Dipl_AutExerc")[0], axis=1)


text:
Q: Embedded Kafka starting with wrong number of partitions I have started an instance of EmbeddedKafka in a JUnit test. I can read the records that I have pushed to my stream correctly in my application, but one thing I have noticed is that I only have one partition per topic. Can anyone explain why?
In my application I have the following:
List<PartitionInfo> partitionInfos = consumer.partitionsFor(topic);

This returns a list with one item. When running against local Kafka with 3 partitions, it returns a list with 3 items as expected.
And my test looks like:
@RunWith(SpringRunner.class)
@SpringBootTest
@EmbeddedKafka(partitions = 3)
@ActiveProfiles("inmemory")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@TestPropertySource(
                locations = "classpath:application-test.properties",
                properties = {"app.onlyMonitorIfDataUpdated=true"})
public class MonitorRestKafkaIntegrationTest {

    @Autowired
    private EmbeddedKafkaBroker embeddedKafkaBroker;

    @Value("${spring.embedded.kafka.brokers}")
    private String embeddedBrokers;

    @Autowired
    private WebApplicationContext wac;

    @Autowired
    private JsonUtility jsonUtility;

    private MockMvc mockMvc;

    @Before
    public void setup() {
            mockMvc = webAppContextSetup(wac).build();
            UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser("dummyUser"));
    }

        private ResultActions interactiveMonitoringREST(String eggID, String monitoringParams) throws Exception {
            return mockMvc.perform(post(String.format("/eggs/%s/interactive", eggID)).contentType(MediaType.APPLICATION_JSON_VALUE).content(monitoringParams));
        }

        @Test
        @WithMockUser("super_user")
        public void testEmbeddedKafka() throws Exception {
            Producer<String, String> producer = getKafkaProducer();
            sendRecords(producer, 3);

            updateConn();

            interactiveMonitoringREST(EGG_KAFKA, monitoringParams)
                    .andExpect(status().isOk())
                    .andDo(print())
                    .andExpect(jsonPath("$.taskResults[0].resultDetails.numberOfRecordsProcessed").value(3))
                    .andExpect(jsonPath("$.taskResults[0].resultDetails.numberOfRecordsSkipped").value(0));
        }

        private void sendRecords(Producer<String, String> producer, int records) {
            for (int i = 0; i < records; i++) {
                String val = "{\"auto_age\":" + String.valueOf(i + 10) + "}";
                producer.send(new ProducerRecord<>(testTopic, String.valueOf(i), val));
            }
            producer.flush();
        }

        private Producer<String, String> getKafkaProducer() {
            Map<String, Object> prodConfigs = new HashMap<>(KafkaTestUtils.producerProps(embeddedKafkaBroker));
            return new DefaultKafkaProducerFactory<>(prodConfigs, new StringSerializer(), new StringSerializer()).createProducer();
        }

        private void updateConn() throws Exception {
            String conn = getConnectionREST(CONN_KAFKA).andReturn().getResponse().getContentAsString();
            ConnectionDetail connectionDetail = jsonUtility.fromJson(conn, ConnectionDetail.class);
            connectionDetail.getDetails().put(ConnectionDetailConstants.CONNECTION_SERVER, embeddedBrokers);
            String updatedConn = jsonUtility.toJson(connectionDetail);
            updateConnectionREST(CONN_KAFKA, updatedConn).andExpect(status().isOk());
        }
    }

A: You need to tell the broker to pre-create the topics...
@SpringBootTest
@EmbeddedKafka(topics = "foo", partitions = 3)
class So57481979ApplicationTests {

    @Test
    void testPartitions(@Autowired KafkaAdmin admin) throws InterruptedException, ExecutionException {
        AdminClient client = AdminClient.create(admin.getConfig());
        Map<String, TopicDescription> map = client.describeTopics(Collections.singletonList("foo")).all().get();
        System.out.println(map.values().iterator().next().partitions().size());
    }

}

Or set the num.partitions broker property if you want the broker to auto-create the topics for you on first use.
We should probably automatically do that, based on the partitions property.

A: I found bootstrapServersProperty is important in @EmbeddedKafka, which is used to populate the property in the application-test.yml, which then can be used to create consumers/listener containers.


text:
Q: Typesafe config: get as map googlesheets{
 dmkb_sheet = "1xEC8CPlKn654321wcoS_JB12345cPPiaA0M"
 other_sheet = "123isS0M30TH3R1D"
}

I would like to use something like myConfig.getAsMap("googlesheets") and get the two nested entries as a Map. No such method exists. So what is the easiest way to load the two nested entries as a Map?

A: OK, that was easy.
myConfig.getConfig("googlesheets").entrySet() does the trick
(I was fixated on the method having a "get" prefix, so missed it)

A: I was after a scala Map[String, String] @Senthil's answer came closest to what I was after but the Map values were quoted i.e. they were enclosed in double quotes and that caused a nasty bug which was not easy to spot. The way I was able to resolve it is by doing configValue.unwrapped().toString() rather than configValue.render()
Before this I tried render() with various ConfigRenderOptions but I did not get the desired result
config
    .getConfig("<key>")
    .entrySet()
    .asScala
    .map(e => e.getKey -> e.getValue.unwrapped().toString)
    .toMap

I am using this in scala and therefore convert it to scala type
Alas, typesafe config which is otherwise a cool library had to make config as Map so hard!

A: For some definition of easy you could use something like this:
val config = conf.atKey("googlesheets")
config.root.keySet.asScala.map(key ⇒ key → config.getString(key)).toMap

I would argue that it would be even easier to use a library for mapping configurations to case classes, like pureconfig

A: Thanks. I got it working by re-writing your answer as follows:
config.entrySet().asScala.map(e => e.getKey -> e.getValue.render()).toMap

A: If someone is looking to read the whole config as Map[String, Any] then the following can be achieved with following recursion.
def configAsMap(config: Config): Map[String, Any] = {
  config
    .entrySet()
    .asScala
    .map { entry =>
      entry.getKey -> unwrappedValue(entry.getValue)
    }
    .toMap
}

def unwrappedValue(value: ConfigValue): Any = value match {
  case l: ConfigList   => l.asScala.map(cv => unwrappedValue(cv))
  case o: ConfigObject => configAsMap(o.toConfig)
  case v               => v.unwrapped()
}

It will load config lists into Scala Seq and config objects as Map[String, ?]. This is useful if one has config structures as following
foo = []
foo += {bar: Bar}
foo += {zoo: Zoo}


text:
Q: Change the data in div periodically on django template I want to change the comments (data) appearing on my page periodically. I have referred to a question here, yet the data is not changing, it does on page refresh though.
Here's my code in views.py
def index(request):
    count = Article.objects.all().count()
    comments = Article.objects.values_list('content')[randint(0, count - 1)][0]
    context = {
        'current_date': datetime.now(),
        'title': 'Home',
        'comments': comments,
    }
    return render(request, 'index.html', context)

And urls.py
urlpatterns = [
    url(r'^$', index, name='index'),
    url(r'^about/$',about),
    # url(r'^comments/$',ArticleCreateView.as_view(), name='comments'),
    url(r'^admin/', admin.site.urls),
]

And index.html

        {{ comments }}

A: Your view index() returns an HTML page, so the argument data contains a whole HTML page.
You probably want to add a second view that returns JSON data only, maybe like this:
views.py
def index_data(request):
    # here you return whatever data you need updated in your template
    return JsonResponse({
        'something_1': 0,
    })

urls.py
url(r'^data$', index_data, name='index-data'),

And then in your AJAX call you do something like this:
url: "{% url 'index-data' %}",
success: function(data) {
    $('#comments').html(data['something_1']);
}

Let us know if that helps.

EDIT
You probably also need to adjust your timer; pass it the function name, but without calling it and also not as a string (see the docs of setInterval):
$(document).ready(function ($) {
    refresh();
    setInterval(refresh, 3000);
});


text:
Q: how can I make my data side by side barplot with dots I have read this post Two horizontal bar charts with shared axis in ggplot2 (similar to population pyramid) and similar ones which could not help me to solve my problem because my data is different. Where I try to explain below
I have a data like below
    dfm<- structure(list(Var1 = structure(1:35, .Label = c("F10", "F11",
"F12", "F13", "F14", "F15", "F16", "F18", "F19", "F2", "F21",
"F25", "F3", "F30", "F35", "F4", "F5", "F58", "F6", "F60", "F7",
"F79", "F8", "F9", "F97", "F117", "F17", "F22", "F23", "F26",
"F31", "F41", "F61", "F67", "F87"), class = "factor"), Freq.x = c(4L,
1L, 2L, 3L, 4L, 1L, 2L, 2L, 1L, 252L, 1L, 2L, 106L, 1L, 1L, 56L,
32L, 1L, 28L, 1L, 17L, 1L, 10L, 7L, 1L, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA), Freq.y = c(12L, 3L, 6L, NA, 7L, NA, 1L, NA,
2L, 306L, 1L, 2L, 170L, NA, NA, 69L, 45L, NA, 35L, NA, 20L, NA,
13L, 7L, NA, 1L, 3L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L)), .Names = c("Var1",
"Freq.x", "Freq.y"), row.names = c(NA, -35L), class = "data.frame")

I have a mutual column named Var1 and two columns Freq.x and Freq.y
I want to plot barplot in vertical ways and put a red or bluedot in top of each bar.
I want to plot the Freq.x in the right side, Freq.y in the left side and the F2 to ... in the middle of both as Y axis
Something like this

I have tried many things but I could not make it.
The closest I got is with the following code
par(mfrow=c(1,2))
barplot(dfm$Freq.y,axes=F,horiz=T,axisnames=FALSE)
axis(side=1,at=seq(1,252,50))
barplot(dfm$Freq.x,horiz=T,axes=T,las=1)

If you just plot the figure as the post mentioned above,
you see that it is giving wrong figure for my data
for example
library(grid)
g.mid<-ggplot(dfm,aes(x=1,y=Var1))+geom_text(aes(label=Var1))+
  geom_segment(aes(x=0.94,xend=0.96,yend=Var1))+
  geom_segment(aes(x=1.04,xend=1.065,yend=Var1))+
  ggtitle("")+
  ylab(NULL)+
  scale_x_continuous(expand=c(0,0),limits=c(0.94,1.065))+
  theme(axis.title=element_blank(),
        panel.grid=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        panel.background=element_blank(),
        axis.text.x=element_text(color=NA),
        axis.ticks.x=element_line(color=NA),
        plot.margin = unit(c(1,-1,1,-1), "mm"))

g1 <- ggplot(data = dfm, aes(x = Var1, y = Freq.x)) +
geom_bar(stat = "identity") + ggtitle("Number of sales staff") +
theme(axis.title.x = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
plot.margin = unit(c(1,-1,1,0), "mm")) +
scale_y_reverse() + coord_flip()

g2 <- ggplot(data = dfm, aes(x = Var1, y = Freq.y)) +xlab(NULL)+
geom_bar(stat = "identity") + ggtitle("Sales (x $1000)") +
theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
axis.text.y = element_blank(), axis.ticks.y = element_blank(),
plot.margin = unit(c(1,0,1,-1), "mm")) +
coord_flip()

library(gridExtra)
gg1 <- ggplot_gtable(ggplot_build(g1))
gg2 <- ggplot_gtable(ggplot_build(g2))
gg.mid <- ggplot_gtable(ggplot_build(g.mid))

grid.arrange(gg1,gg.mid,gg2,ncol=3,widths=c(4/9,1/9,4/9))

See the plot
and look at for example the F2 values for both dfs
you see? both are the highest values but in this plot they show the least
about the second answer. they guy Melted the data and it made me crazy to melt my data
so I could not figure it out how to plot it based on that
about the third, it is completely out of my interest because I only need one plot with my data and not splitting it
after assigning the g.mid , it does not take the order into account , it starts from 87 to the end while the order of my dfmstarts from 2

A: For the red and blue dots. You can add +geom_point(aes(x = Var1, y = Freq.x),shape=19,size=6,color="red")+and geom_point(aes(x = Var1, y = Freq.y),shape=19,size=6,color="blue")+. Try this code (with @cuttlefish44 's help):
library(dplyr)
ind <- gsub("F", "", dfm$Var1) %>% as.numeric() %>% order(decreasing = T)
newlev <- levels(dfm$Var1)[ind]
dfm$Var1 <- factor(dfm$Var1, levels = newlev)
library(grid)
g.mid<-ggplot(dfm,aes(x=1,y=Var1))+geom_text(aes(label=Var1))+
  geom_segment(aes(x=0.94,xend=0.96,yend=Var1))+
  geom_segment(aes(x=1.04,xend=1.065,yend=Var1))+
  ggtitle("")+
  ylab(NULL)+
  scale_x_continuous(expand=c(0,0),limits=c(0.94,1.065))+
  theme(axis.title=element_blank(),
        panel.grid=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        panel.background=element_blank(),
        axis.text.x=element_text(color=NA),
        axis.ticks.x=element_line(color=NA),
        plot.margin = unit(c(1,-1,1,-1), "mm"))
g1 <- ggplot(data = dfm, aes(x = Var1, y = Freq.x)) +
  geom_bar(stat = "identity") + ggtitle("Number of sales staff") +
  geom_point(aes(x = Var1, y = Freq.x),shape=19,size=6,color="red")+
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        plot.margin = unit(c(1,-1,1,0), "mm")) +
  scale_y_reverse() + coord_flip()
g2 <- ggplot(data = dfm, aes(x = Var1, y = Freq.y)) +xlab(NULL)+
  geom_bar(stat = "identity") + ggtitle("Sales (x $1000)") +
  geom_point(aes(x = Var1, y = Freq.y),shape=19,size=6,color="blue")+
  theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
        axis.text.y = element_blank(), axis.ticks.y = element_blank(),
        plot.margin = unit(c(1,0,1,-1), "mm")) +
  coord_flip()
library(gridExtra)
gg1 <- ggplot_gtable(ggplot_build(g1))
gg2 <- ggplot_gtable(ggplot_build(g2))
gg.mid <- ggplot_gtable(ggplot_build(g.mid))

grid.arrange(gg1,gg.mid,gg2,ncol=3,widths=c(4/9,1/9,4/9))

UPDATE Nº4
In this example, I modify the labels. Try this code:
library(ggplot2)
library(dplyr)
ind <- gsub("F", "", dfm$Var1) %>% as.numeric() %>% order(decreasing = T)
newlev <- levels(dfm$Var1)[ind]
dfm$Var1 <- factor(dfm$Var1, levels = newlev)
#labeling 35 levels to 7 levels
library(plyr)
each5<-levels(dfm$Var1)
interval<-rep(c(rep(c(FALSE),each=4),TRUE),length.out= 35)
dfm$Var2<-c("")
for (i in 1:length(dfm$Var1)){
  if (dfm$Var1[i] %in% each5[interval])
      dfm$Var2[i]<-as.character(dfm$Var1[i])
}
library(grid)
g.mid<-ggplot(dfm,aes(x=1,y=Var1))+
  geom_text(aes(label= Var2),fontface=2)+
  geom_segment(aes(x=0.94,xend=0.96,yend=Var1))+
  geom_segment(aes(x=1.04,xend=1.065,yend=Var1))+
  ggtitle("")+
  ylab(NULL)+
  scale_x_continuous(expand=c(0,0),limits=c(0.94,1.065))+
  scale_y_discrete(labels=c("F2" = "Dose 0.5", "F10" = "Dose 1",
                            "F21" = "Dose 2"))+
  theme(axis.title=element_blank(),
        panel.grid=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        panel.background=element_blank(),
        axis.text.x=element_text(color=NA),
        axis.ticks.x=element_line(color=NA),
        plot.margin = unit(c(1,-1,1,-1), "mm"))
g1 <- ggplot(data = dfm, aes(x = Var1, y = Freq.x)) +
  geom_bar(stat = "identity") + ggtitle("Number of sales staff") +
  geom_point(aes(x = Var1, y = Freq.x),shape=19,size=6,color="red")+
  expand_limits(y =600) +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        plot.margin = unit(c(1,-1,1,0), "mm")) +
  scale_y_reverse() + coord_flip()
g2 <- ggplot(data = dfm, aes(x = Var1, y = Freq.y)) +xlab(NULL)+
  geom_bar(stat = "identity") + ggtitle("Sales (x $1000)") +
  geom_point(aes(x = Var1, y = Freq.y),shape=19,size=6,color="blue")+
  expand_limits(y =600) +
  theme(axis.title.x = element_blank(), axis.title.y = element_blank(),
        axis.text.y = element_blank(), axis.ticks.y = element_blank(),
        plot.margin = unit(c(1,0,1,-1), "mm")) +
  coord_flip()
library(gridExtra)
gg1 <- ggplot_gtable(ggplot_build(g1))
gg2 <- ggplot_gtable(ggplot_build(g2))
gg.mid <- ggplot_gtable(ggplot_build(g.mid))

grid.arrange(gg1,gg.mid,gg2,ncol=3,widths=c(4/9,1/9,4/9))

A: Look at levels(dfm$Var1). It causes your problem. You need to change its order. (I don't have a good idea about ellipses.)
library(dplyr)

ind <- gsub("F", "", dfm$Var1) %>% as.numeric() %>% order(decreasing = T)
newlev <- levels(dfm$Var1)[ind]
dfm$Var1 <- factor(dfm$Var1, levels = newlev)


text:
Q: How to issue GET request to Google from an ESP32? (can't get it to work) I´m trying to get an ESP32 to send GET requests to Google, but all I get is a -1 error response from the server. I'm using the Arduino IDE for this.
The reason behind the query to google is to get a basic setup on the ESP32 working. Based on that I will then need to modify it so that it sends a GET to our company's application running on App Engine.
After establishing a connection to my WiFi, I have the following code to generate the GET request:
if(WiFi.status()== WL_CONNECTED){
  HTTPClient http;

  // Domain name with URL path or IP address with path
  http.begin("google.com");

  // Send HTTP GET request
  int httpResponseCode = http.GET();

  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    String payload = http.getString();
    Serial.println(payload);
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  // Free resources
  http.end();
}
else {
  Serial.println("WiFi Disconnected");
}

Any ideas what I'm doing wrong?
Once I have a way to get the above working, I would like to send a query to google. Would the following be the right way?
      http.begin("google.com?search=ESP32");

Thanks!
Edited after first feedback:
I changed the following line to include full URI:
  // Domain name with URL path or IP address with path
  http.begin("google.com");

And now I get a 404 error:
HTTP Response code: 404
That's an error
The requested URL ./1.1 was not found on this server.  That's all we know
(Omitted the css tags for brevity)

A: If you read the example code, then you'll notice that it specifies the address as an absolute URI (http://example.com/index.html), not a domain name only (example.com).
        http.begin("http://example.com/index.html"); //HTTP


text:
Q: Dealing with non-standard SMTP ports with sendmail -t On my development machine, I have a special kind of SMTP server running on non-standard port which is used for testing purposes.
On my virtual machine I'm trying to push a message to that SMTP server by using Exim4's sendmail app:
selenium-node$ sendmail -t
To: root@my-development-machine.testingnetwork.local:2525
From: apache@my-selenium-node.testingnetwork.local
Subject: Test message

Quick brown fox jumps over the lazy dog
selenium-node$

However, it looks that default SMTP server on my-development-machine.testingnetwork.local:25 receives my message instead.
Is there a clean and natural way to do what I'm trying for? Modifying some configs on my-selenium-node.testingnetwork.local is no problem.

A: SMTP always goes to TCP/25 unless the mail delivery agent (here, sendmail as implemented by Exim) is specifically configured to send the mail to some custom port. There is no means to set the port like there is in URL from the mail user agent that talks to the mail delivery agent. Options thus are limited to reconfiguring Exim to send to a different port or to use some other mail sending program to direct the mail elsewhere, such as ssmtp with configuration in ssmtp.conf along the lines of
mailhub=my-development-machine.testingnetwork.local:2525

and then piping the message to ssmtp. Another option would be to use a SMTP client module in some programming language; these may support sending to arbitrary TCP ports.


text:
Q: PCI BAR memory addresses Quick question, I was reading the OSDev Wiki page regarding PCI and it says the following -

Base address Registers (or BARs) can be used to hold memory addresses used by the device, or offsets for port addresses. Typically, memory address BARs need to be located in physical ram while I/O space BARs can reside at any memory address (even beyond physical memory).`

I don't get where it says memory address BARs need to be located in physical ram. The whole point of MMIO is that it gets assigned a memory address so that it will be routed to the device and not into physical RAM. What does it mean by it needs to be located in physical RAM?
Wouldn't it just be an address between the 3GB - 4GB address space, regardless of how much physical RAM is installed?
Is this an error on the OSDev site or have I misunderstood?
link - About halfway down, under the heading Base Address Registers

A: I believe there is some confusion here, as there is a difference between I/O and non-I/O devices.
From wikipedia Memory-mapped I/O (MMIO) :

Memory-mapped I/O
  uses the same address bus to address both memory and I/O devices – the
  memory and registers of the I/O devices are mapped to (associated
  with) address values. So when an address is accessed by the CPU, it
  may refer to a portion of physical RAM, but it can also refer to
  memory of the I/O device. Thus, the CPU instructions used to access
  the memory can also be used for accessing devices. Each I/O device
  monitors the CPU's address bus and responds to any CPU access of an
  address assigned to that device, connecting the data bus to the
  desired device's hardware register. To accommodate the I/O devices,
  areas of the addresses used by the CPU must be reserved for I/O and
  must not be available for normal physical memory.

From your article :

Base address Registers (or BARs) can be used to hold memory addresses
  used by the device, or offsets for port addresses. Typically, memory
  address BARs need to be located in physical ram while I/O space
  BARs can reside at any memory address (even beyond physical memory).

The Type field of the Memory Space BAR Layout specifies the size of
  the base register and where in memory it can be mapped. If it has a
  value of 0x00 then the base register is 32-bits wide and can be mapped
  anywhere in the 32-bit Memory Space. A value of 0x02 means the base
  register is 64-bits wide and can be mapped anywhere in the 64-bit
  Memory Space (A 64-bit base address register consumes 2 of the base
  address registers available).

Thus there is no conflict between the two, as it all depends on the device.
If the device intercepts the memory reference on the bus, then the address is virtual.
If it doesn't, then it's real physical address that is used to communicate with the device
(for example NVRAM).
However, in all cases, real physical address is used for I/O devices, since computer instructions that refer to it can only use real addresses.
This memory may be wasted if the device intercepts references to it.
To avoid such waste, the operating system will usually allocate it beyond the
real physical memory (this will cause no errors of bad memory access,
since the device will intercept all references).
This is the reason for the well-known problem of 32-bit Windows computers
not seemingly being able to use the entire 4 GB of memory.
The reason was that Windows, being 32-bit, allocated device memory using real addresses,
which then became unavailable for both the cases:
whether the addressed memory was really used,
or unused because intercepted by the device.
Another useful wikipedia article is : PCI configuration space.

A: The address bus width determines the size of the physical address space. But not all the values within this space are claimed by memory controllers. Some are claimed by other types of devices. The BAR register implicitly encoded the address range size requested by the PCIe device/function. But where the base of this range is must be properly configured. Then the device can automatically claim the request with the address falling into its range. This arrangement is all configurable during the system initialization/boot phase.
An useful illustration:

From the perspective of a software engineer, I think the most important thing to know is not how all these plumbing is implemented for a computing architecture. But by what means the hardware resource is exposed to software. For x86 architecture, it can be memory address, or IO address.


text:
Q: Using Field Calculator in ArcMap Using the field calculator of ArcMap, I know I need to use a text qualifier "" for string, and if numbers are in a text field (at least for VB Script which is what we are learning in).
Is there a specific reason for this and why don't you have to use it for numeric fields?

A: This is entirely due to the syntax of the programming language you are using (in this case VB Script, but it is much the same for other - eg, in Python, you can use either " or ').
The value that you enter in the 'Expression' parameter in the field calculator is really just an expression (sort of a one-line program) in your programming language of choice.  In the vast majority of programming languages, a number is interpreted literally as a number, a " or ' delimited string of text is interpreted a literal text and anything else is either a reserved word (ie, a word which has a special meaning in the language), a variable or function name, or an operator (eg, +, -).
So in most languages, "16" is not a number, but a text string represented by two characters of text (and likely stored as two ACII or Unicode representations of those characters).  But 16 is actually a number and is stored as the binary representation of that number, not a text encoding of the two digit characters.
In programming languages, types matters.  Number values (eg, int, real, double, float) are treated completely differently to text string values.
You can use either text or numbers in the Field Calculator expression, but in some contexts, the result will be different depending on what you do with them.  Eg, In most languages, "16" + "4" is completely different to 16 + 4.  (I'm not familiar with VB Script, preferring Python, but I think that in VB Script the + operator will actually cause the string values to be re-interpret as numbers, so the result may actually end up the same in this example?)


text:
Q: Authentication with cookies in react I am creating a login authentication function using React and will employ cookies as the authentication method.
Which is the best way to do this, to receive the token on the front side, store it in a cookie, or pass it to the backend (node.js), and which is more common, to send the cookie from the front side or to send and check the cookie from the request on the backend side? What is more common?


text:
Q: How to get the parameter value and assign to agent in source block I have an agent with parameters AccountNo, start date,end_date ,Value,type_of_account,cycle_time.
For AccountNo I have created a custom distribution based on the actual data. So when an agent is generated at source block it will be assigned an AccountNo value. Now before agent leaves source block i want to update other parameter from the SQL table
SQL table has AccountNo , Value,type_of_account, Cycle_time fields.
On exit at source I want to update the agent parameters as below:

*

*agent.start_date=date()

*agent.end_date=  agent.start_date+ cycle_time (from SQL table for same agent based on same account no)

*agent.type_of_acount=type_of_account (from sql table with corresponding value based on same account No)
How I can assign the parameter values from SQL table? I tried
writing query to get the value from db.

.
 ((MyAgent1)agent).start_time=date();

  double a= ((MyAgent1)agent).actno;

  double b = selectFirstValue(false, double.class, "SELECT cycle_time FROM sheet1 WHERE actno = a;");

It is throwing error

user lacks privilege or object not found

is there a good way to update parameter values ?


text:
Q: When should I use a bitwise operator? I read the following Stack Overflow questions, and I understand the differences between bitwise and logical.

*

*Difference between & and && in PHP

*Reference - What does this symbol mean in PHP?
However, none of them explains when I should use bitwise or logical.
When should I use bitwise operators rather than logical ones and vice versa?
In which situation do I need to compare bit by bit?
I am not asking about the differences, but I am asking the situation when you need to use bitwise operators.

A: Bitwise operators are specifically used in case of binary value representation.
echo '0110011010' & '0101001001';
//0100001000

Logical operators are most preferred for comparison and are a bit faster than bitwise operator in case of AND and XOR operations.
if(func1() && func2())

if func1() returns false it won't bother calling func2()
if(func1() & func2())

Will call both functions regardless of their returned values.

A: In most cases, you'll probably want to use logical operators.  They're used for combining logical conditions, generally to control program flow, e.g. ($isAlive && $wantsToEat).
Bitwise operators are used when you want to perform operations on a bit-by-bit basis on the underlying binary representations of integers.  e.g.  (5 & 3) == 7.  As others have suggested, there's usually not a lot of call for this in the sort of application that tends to get written in PHP (although there is in lower-level languages, like C).

A: Bitwise operators are useful when manipulating the bits of a number. Look here. Otherwise you should use the logical operators. Also the logical operators are short-circuited. For example, if you have a && b and a is false, b is not evaluated.
Disclaimer: I am coming from a Java background, but I guess in PHP it is the same.

A: Bitwise is useful for things in PHP just like anything else.
How about a value that can have multiple states turned on at the same time?
<?php

// since we're setting constant values in base10 we must progressively double
// them since bitwise operations work in base2. you'll see why when we output
// these as binary values below.
const STATE_FOO = 1;
const STATE_BAR = 2;
const STATE_FEZ = 4;
const STATE_BAZ = 8;

// show base2 values of the above constants
echo sprintf("STATE_FOO's base2 value is %08d\n", decbin(STATE_FOO));
echo sprintf("STATE_BAR's base2 value is %08d\n", decbin(STATE_BAR));
echo sprintf("STATE_FEZ's base2 value is %08d\n", decbin(STATE_FEZ));
echo sprintf("STATE_BAZ's base2 value is %08d\n\n", decbin(STATE_BAZ));

// set state to FOO and FEZ
$state = STATE_FOO | STATE_FEZ;

echo sprintf("base10 value of \$state is %s\n", $state);
echo sprintf("base2 value of \$state is %08d\n", decbin($state));
echo sprintf("Does \$state include FOO state? %s\n", (bool)($state & STATE_FOO));
echo sprintf("Does \$state include BAR state? %s\n", (bool)($state & STATE_BAR));
echo sprintf("Does \$state include FEZ state? %s\n", (bool)($state & STATE_FEZ));
echo sprintf("Does \$state include BAZ state? %s\n", (bool)($state & STATE_BAZ));
echo sprintf("Is state equivalent to FOO and FEZ states? %s\n", ($state == (STATE_FOO | STATE_FEZ)));

Output:
STATE_FOO's base2 value is 00000001
STATE_BAR's base2 value is 00000010
STATE_FEZ's base2 value is 00000100
STATE_BAZ's base2 value is 00001000

base10 value of $state is 5
base2 value of $state is 00000101
Does $state include FOO state? 1
Does $state include BAR state?
Does $state include FEZ state? 1
Does $state include BAZ state?
Is state equivalent to FOO and FEZ states? 1

A: Forget what is already in your head.
OK, now say you have some different roles: admin, user, and guest.
and some different permissions: read, write and delete
Let's create some bitmasks for permissions and roles. A bitmask is a sequence of bits that can be used to manipulate or read some kind of flags. As shown below:
// flags                                bitmasks
$read = 1;                              // 0001
$write = 2;                             // 0010
$delete = 4;                            // 0100

$admin = $read | $write | $delete;      // 0001 | 0010 | 0100 => 0111
$user = $read | $write;                 // 0001 | 0010 => 0011
$guest = $read;                         // 0001 => 0001

Notice 1, 2, 4. This must be raised as double. Otherwise, it might give you some awkward results.
Forget about the things commented. Those are just sequence of bits (or bitmasks) for individual permissions and roles.
Now let's create a handy function which may be used to check a specific permission for a specific role.
function isAllowed($role, $permissison) {
    return $role & $permissison ? true : false;
}

We are done. Let's check the $delete permission for all 3 roles:
var_dump(isAllowed($admin, $delete));  // bool(true)
var_dump(isAllowed($user, $delete));   // bool(false)
var_dump(isAllowed($guest, $delete));  // bool(false)

So why is bitwise operation? In a word, bitwise operation is more faster, concise and maintainable. Otherwise, using bitwise operation is always efficient for complex applications.

A: Bitwise | and & and logical || and && are totally different.
Bitwise operators perform operations on the bits of two numbers and return the result. That means it's not a yes or no thing. If they're being used in conditional statements, they're often used as part of logical comparisons. For example:
if ($x & 2 == 2) {
    // The 2^1 bit is set in the number $x
}

Logical operators compare two (or more) conditions/expressions and return true or false. You use them most commonly in conditional statements, like if and while. For example:
if ($either_this || $or_this) {
    // Either expression was true
}

A: They are two very different operators.
When you want two conditions to simultaneously be true, you use the logical &&. For example, I want to print out "happy birthday" only if the person's birthday is today && they have money in the account. This is used whenever we want to perform composition of two or more conditions, mostly in if statements and loop conditions (although not exclusively).
When you want to perform bitwise operations (which in day-to-day PHP programming is much more rare), you use the bitwise &. This is far more rare, and you might be performing bitwise masking (I doubt it though), so you might only want a result that both integers represent, in which case you can say newAttribute = attribute1 & attribute2;.

A: Well, asuming there is $x = (false && some_function());, here the value of $x will be set without calling the some_function() because the first value was FALSE.
But what if you needed to call that function anyway? Use $x = (false & some_function());.
In other words, the & uses MORE processing than the &&, just because && does not run through all the values to check them. If it found one value as false, it would return it, not looking at other values.
And in logical operations, use the && operator as it's used to return the logical operation value, where & is used to set a value and in an if statement it will always return true.


text:
Q: Picking a random option, where each option has a different probability of being picked Suppose that you are given three "options", A, B and C.
Your algorithm must pick and return a random one. For this, it is pretty simple to just put them in an array {A,B,C} and generate a random number (0, 1 or 2) which will be the index of the element in the array to be returned.
Now, there is a variation to this algorithm: Suppose that A has a 40% chance of being picked, B a 20%, and C a 40%. If that was the case, you could have a similar approach: generate an array {A,A,B,C,C} and have a random number  (0, 1, 2, 3, 4) to pick the element to be returned.
That works. However, I feel that it is very inefficient. Imagine using this algorithm for a large amount of options. You would be creating a somewhat big array, maybe with 100 elements representing a 1% each. Now, that's still not quite big, but supposing that your algorithm is used many times per second, this could be troublesome.

I've considered making a class called Slot, which has two properties: .value and .size. One slot is created for each option, where the .value property is the value of the option, and the .size one is the equivalent to the amount of occurrences of such option in the array. Then generate a random number from 0 to the total amount of occurrences and check on what slot did the number fall on.
I'm more concerned about the algorithm, but here is my Ruby attempt on this:
class Slot
  attr_accessor :value
  attr_accessor :size
  def initialize(value,size)
    @value = value
    @size  = size
  end
end

def picker(options)
  slots = []
  totalSize = 0
  options.each do |value,size|
    slots << Slot.new(value,size)
    totalSize += size
  end
  pick = rand(totalSize)
  currentStack = 0
  slots.each do |slot|
    if (pick <= currentStack + slot.size)
      return slot.value
    else
      currentStack += slot.size
    end
  end
  return nil
end

50.times do
  print picker({"A" => 40, "B" => 20, "C" => 40})
end

Which outputs:

CCCCACCCCAAACABAAACACACCCAABACABABACBAAACACCBACAAB

Is there a more efficient way to implement an algorithm that picks a random option, where each option has a different probability of being picked?

A: As a first approximation to a more efficient algorithm, if you compute the cumulative distribution function (which is just one pass over the distribution function, computing a running sum), then you can find the position of the randomly chosen integer using a binary search instead of a linear search. This will help if you have a lot of options, since it reduces the search time from O(#options) to O(log #options).
There is an O(1) solution, though. Here's the basic outline.
Let's say we have N options, 1...N, with weights ω1...ωN, where all of the ω values are at least 0. For simplicity, we scale the weights so their mean is 1, or in other words, their sum is N. (We just multiply them by N/Σω. We don't actually have to do this, but it makes the next couple of paragraphs easier to type without MathJax.)
Now, create a vector of N elements, where each element has a two option identifiers (lo and hi) and a cutoff p. The option identifiers are just integers 1...N, and p will be computed as a real number in the range (0, 1.0) inclusive.
We proceed to fill in the vector as follows. For each element i in turn:

*

*If some ωj is exactly 1.0, then we set:
   loi = j
   hii = j
   pi  = 1.0
And we remove ωj from the list of weights.

*Otherwise, there must be some ωj < 1.0 and some ωk > 1.0. (That's because the average weight is 1.0, and none of them have the average value. Some some of them must have less and some of them more, because it is impossible for all elements to be greater than the average or all elements to be less than the average.) Now, we set:
   loi = j
   hii = k
   pi  = ωj
   ωk = ωk - (1 - ωj)
And once again, we remove ωj from the weights.
Note that in both cases, we have removed one weight, and we have reduced the sum of the weights by 1.0. So the average weight is still 1.0.
We continue in this fashion until the entire vector is filled. (The last element will have p = 1.0).
Given this vector, we can select a weighted random option as follows:

*

*Generate a random integer i in the range 1...N and a random floating point value r in the range (0, 1.0]. If r < pi then we select option loi; otherwise, we select option hii.

It should be clear why this works from the construction of the vector. The weights of each above-average-weight option are distributed amongst the various vector elements, while each below-average-weight option is assigned to one part of some vector element with a corresponding probability of selection.
In a real implementation, we would map the range of weights onto integer values, and make the total weights close to the maximum integer (it has to be a multiple of N, so there will be some slosh.) We can then select a slot and select the weight inside the slot from a single random integer. In fact, we can modify the algorithm to avoid the division by forcing the number of slots to be a power of 2 by adding some 0-weighted options. Because the integer arithmetic will not work out perfectly, a bit of fiddling around will be necessary, but the end result can be made to be statistically correct, modulo the characteristics of the PRNG being used, and it will execute almost as fast as a simple unweighted selection of N options (one shift and a couple of comparisons extra), at the cost of a vector occupying less than 6N storage elements (counting the possibility of having to almost double the number of slots).

A: While this is not a direct answer I will show you a source for help you outline this problem: http://www.av8n.com/physics/arbitrary-probability.htm.
Edit:
Just found a nice source in ruby for that, pickup gem.
require 'pickup'
headings = {
  A: 40,
  B: 20,
  C: 40,
}
pickup = Pickup.new(headings)
pickup.pick
#=> A
pickup.pick
#=> B
pickup.pick
#=> A
pickup.pick
#=> C
pickup.pick
#=> C

A: The simplest way is probably to write a case statement:
def get_random()
  case rand(100) + 1
    when  1..50   then 'A'
    when 50..75   then 'B'
    when 75..100  then 'C'
  end
end

The problem with that is that you cannot pass any options, so you can write a function like this if you want it to be able to take options. The one below is very much like the one you wrote, but a bit shorter:
def picker(options)
  current, max = 0, options.values.inject(:+)
  random_value = rand(max) + 1
  options.each do |key,val|
     current += val
     return key if random_value <= current
  end
end

# A with 25% prob, B with 75%.
50.times do
  print picker({"A" => 1, "B" => 3})
end
# => BBBBBBBBBABBABABBBBBBBBABBBBABBBBBABBBBBBABBBBBBBA

# If you add upp to 100, the number represent percentage.
50.times do
  print picker({"A" => 40, "T" => 30, "C" => 20, "G" => 10})
end
# => GAAAATATTGTACCTCAATCCAGATACCTTAAGACCATTAAATCTTTACT


text:
Q: How to make pixel operations on canvas faster in Javascript I am writing a program to convert three equations into an image by using them to generate RGB values for each pixel on a canvas. This is the code of my first test:

const canvas = document.getElementById("game")
const context = canvas.getContext("2d")

time = new Date()

canvas.width = 500
canvas.height = 500

for (x = 0; x < canvas.width; x++) {
  for (y = 0; y < canvas.height; y++) {
    context.fillStyle = "red"
    context.fillRect(x, y, 1, 1)
  }
}

console.log(new Date() - time)
<canvas id="game"></canvas>

However, when I run this code it takes a few seconds to generate the canvas. I added a basic way to see how long the code takes to run, and the console appears to say it only takes 200 milliseconds. I have noo idea why it says it only takes 200 milliseconds as I do not see the canvas until a few seconds after the console log.
How can I make these pixel operations faster?

A: If you're just using a single color, you can speed it up a bit by setting the fillStyle before the loop instead of setting it every iteration. That obviously won't work if you want to set different colors for different pixels, however.
You could also set the colors in an imageData object, then draw it all at once with putImageData. This is significantly faster for me in both Chrome and Firefox.

const canvas = document.getElementById("game")
const context = canvas.getContext("2d")

time = new Date()

canvas.width = 500
canvas.height = 500

let imageData = context.createImageData(canvas.width, canvas.height)
let data = imageData.data;
let i = 0;
while (i < data.length) {
  data[i++] = 255; // Red value
  data[i++] = 0; // Green value
  data[i++] = 0; // Blue value
  data[i++] = 255; // Alpha (opacity)
}
context.putImageData(imageData, 0, 0)
console.log(new Date() - time)
<canvas id="game"></canvas>


text:
Q: My route isnt being founded for some reason My code is below, I just have a simple setup for now to make sure my routes are working but im encountering a 404 error. I have an app.all thats catching the error but i dont know where the error is happening at.
heres my index.js file where I have my express server setup running the error catching app.all is in this file
const express = require('express')
const cors = require('cors')
const app = express()
const PORT = process.env.PORT || 8000

app.use(cors())
app.use(express.urlencoded({ extended: true }))

const userRoutes = require('./routes/users.js')

app.get('/', (req, res) => {
    res.send('backened is up')
})

app.use('/', userRoutes)

app.all('*', (req, res, ) => res.send('That route does not exist!'))

app.listen(PORT, () => console.log(`Server running on port ${PORT}`))

heres my routes file where im retrieving the data from the users file.
const express = require('express');
const { getUsers, createUser, deleteUser } = require('../controllers/users.js')
const router = express.Router();

router.get('./users', getUsers)
router.post('./user', createUser)

module.exports = router;

and lastly heres my users file inside my controllers file where im setting up data for the client side
const {v4 : uuidv4} = require('uuid')

let users = []

exports.getUsers = (req, res) => {

    try {
        res.send(users)
    } catch (error) {
        console.error(error)
    }
}

exports.createUser = (req, res) => {
    try {
        const user  = req.body

        users.push({...user, id: uuidv4()})

        res.send("User Added Successfully!")

    } catch (error) {
        console.error(error)
    }
}

A: Change these:
router.get('./users', getUsers)
router.post('./user', createUser)

to this:
router.get('/users', getUsers)
router.post('/user', createUser)

You don't use ./ and ../ in route definitions. Route paths are already relative to whatever the path was when the request was sent to that router.


text:
Q: Connection from local Wordpress with local external SQL Server database I have set up a local Wordpress installation on my macbook. Know I want to display data from an existing external local database (SQL Server) with queries. How can I solve this problem? I have access to the database with Azure Data Studio
I created my own theme (blank site) and activated it, know I want a connection:
    <?php
error_reporting(E_ALL);

define ( 'MYSQL_HOST',      'localhost' );
define ( 'MYSQL_BENUTZER',  'user' );
define ( 'MYSQL_KENNWORT',  '' );
define ( 'MYSQL_DATENBANK', '' );

$db_link = mysqli_connect (MYSQL_HOST,
                           MYSQL_BENUTZER,
                           MYSQL_KENNWORT,
                           MYSQL_DATENBANK);

if ( $db_link )
{
    echo 'Verbindung erfolgreich: ';
    print_r( $db_link);
}
else
{
    die('keine Verbindung möglich: ' . mysqli_error());
}
?>

A: Wordpress does not natively support MS SQL Server. However, a team of SQL Server developers created and maintain Project Nami as a fork of the platform that supports SQL Server and Azure.
The most recent version of Project Nami uses Wordpress 5.5.1 (current version). I suggest reviewing the Project Nami's plugin compatibility page to check for unsupported plugins.
The source code of the project is available at Project Nami's GitHub repository.


text:
Q: java.lang.UnsatisfiedLinkError: jMQ (Not found in java.library.path) I have Java Code to load the library of C(32-bit) and I have AIX 7.1 system which has 32 bit java-6 to run the Java Code. But I am getting an following exception.
Code :
public class NativeMQChannel {

    static {
        // String jMQlibPath = System.getenv("JMQLIBPATH");
        // String libraryFile = (jMQlibPath != null ? jMQlibPath : "");
        // libraryFile = libraryFile + "jMQ";
        System.loadLibrary("jMQ");
    }

Exception:

Exception in thread "ActiveMQ Session Task-2" java.lang.UnsatisfiedLinkError: jMQ (Not found in java.library.path)
    at java.lang.ClassLoader.loadLibraryWithPath(ClassLoader.java:1034)
    at java.lang.ClassLoader.loadLibraryWithClassLoader(ClassLoader.java:1004)
    at java.lang.System.loadLibrary(System.java:507)
    at com.ecs.middleware.channel.NativeMQChannel.<clinit>(NativeMQChannel.java:19)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:199)

Any solution?


text:
Q: Multilingual iApp in a difficult/special environment There are a great number of tutorials that tell you how to write multilingual apps for the iPhone. I haven't found one though that deals with my particular problem...
There must be a way how an iPhone app can enforce a certain default language if the user runs the iPhone with neither of the languages supported by the app?
Here in Switzerland we speak German, French and Italian (in different parts of the country). German can be considered the "default" language because its share is nearly 65%. Hence, any national retailer has his product descriptions in these three languages. We built an iApp that supports these three languages.
So far so good...as long as users have selected either of the three languages in their iPhone settings everything works as expected. For users that use the iPhone in English, that seems to be a significant number, this goes wrong because the application is displayed in French instead of German (the assumed default language).
Why? Because French by default is higher up in the list of available languages in the iPhone settings than German. The workaround for users is to switch the iPhone from English to German and back. The iPhone places German second in the list of available languages.
How should the app best deal with that? Ahh, of course we could support English for UI elements but our customer's product descriptions simply aren't available in English. Hence, this isn't really an option.

A: I came up with the same problem some time ago. My way of solving it was to set all the localizable elements programmatically and not rely on the iOS localization at all. I implemented my own language manager that handles localized strings (read from a custom resource file) and tries to choose the best language for the current device (using the rules provided in a custom preference file). Of course, if the current preferred language of the device is available among the localizations, it has the highest priority. I also leave an opportunity to change the language in settings.

A: You can let user choose which language to use in app and set it like this:
NSArray *lang = [NSArray arrayWithObjects:@"de", nil];
[[NSUserDefaults standardUserDefaults] setObject:lang forKey:@"AppleLanguages"];


text:
Q: Not let UIButton drag outside Circle I am new to ios.
I have a view in which i had drawn a circle using Quarts core.
I had put one UIButton in that circle and given the Funcnality to DRag and drop that button.
Now i want constraint that the button cant be draged out of that circle area.
The TouchDragOutSide Event of Button is
- (void) draggedOut: (UIControl *) c withEvent: (UIEvent *) ev
{
    if([viewCanvas pointInside:[[[ev allTouches] anyObject] locationInView:viewCanvas ] withEvent:ev])
        c.center = [[[ev allTouches] anyObject] locationInView:viewCanvas ];

}

At this point the button cant be drag out side of rectangle View area.
Thanks for Help

A: try this..
if([viewCanvas pointInside:[[[ev allTouches] anyObject] locationInView:viewCanvas ] withEvent:ev])
{
UITouch *touch = [[ev touchesForView:c] anyObject];

CGPoint location = [touch locationInView:c];

if((location.x<(viewCanvas.frame.origin.x+viewCanvas.frame.size.width))&&(location.y<(viewCanvas.frame.origin.y+viewCanvas.frame.size.height)))
{
  c.center = [[[ev allTouches] anyObject] locationInView:viewCanvas ];

}
}

A: I had make solution by the equation by using this equation.
(x-center_x)^2 + (y - center_y)^2 < radius^2

A: you have the  center (x,y) of circle and radius. take the center of the button and check whether it is inside of your x+ radius - width/2 if it moves in x direction and y+ radius - height/2 if it in a y direction. check for the 4 directions and give proper + / -


text:
Q: Is there a plugin for Wordpress that lets me show HTML/JS/CSS examples? Are there any Wordpress plugins that let me show inline in a page or a post some HTML, Javascript and CSS, and let the user see it running as well as see the code? Essentially I'm looking for something a little bit like a JSFiddle that I can render inline as a way to demonstrate how certain functionality works.
Thanks in advance!

A: I would just embed a jsfiddle. It allows you to see all the code, and run the result.
Take a look here for docs: http://doc.jsfiddle.net/use/embedding.html
And an example embed: http://bit.ly/1aFKGO7


text:
Q: Nested flex containers with inner scroll bar and snug/covering lower container I have a nested structure of flexbox containers, where an inner container needs to show potentially large content in a scrollable pane. However, sometimes the content is small.
There's an additional container that needs to be always visible, and that I'd like to have just below the scrollable content, i.e. not far down at the bottom unless the scrollable pane content "pushes" it down - the viewport can be much larger than the content.
What I have right now does everything except have the "Right bottom" come up when the "Right top content" is small:
JsFiddle: https://jsfiddle.net/u6dou3wf/10/

.main {
  display: flex;
  height: 200px;
}

.left {
  flex: 1 1 0;
  background: red;
}
.right {
  flex: 0 0 0;
  display:flex;
  flex-direction: column;
  background: green;
  padding: 4px;
}

.right-top-wrapper {
  flex: 1 1 0;
  overflow-x: auto;
  overflow-y: scroll;
  background: blue;
}

.right-top-content {
  margin: 4px;
  height:100px;
  width:100px;
  background: pink;
}

.right-bottom {
  flex: 0 0 0;
  background: yellow;
  margin: 4px;
}

 Left content

    Right top content

   Right bottom

How can I get the "Right bottom" to be snugly below the "Right top content", i.e. get the blue section to shrink if the pink section is small, and then grow to whatever size is available inside the green (minus yellow) if the pink section is large?
I have tried .right-top-wrapper { flex: 0 1 0; } but then it shrinks to nothing (a consequence of overflow-y: scroll or auto, which I have to have to allow large "Right top content").

A: Okay, After having a quick fiddle, and if i am right in thinking of what you want to achieve, Change your CSS:
.main {
  display: flex;
  height: 200px;
}

.left {
  flex: 1 1 auto;
  background: red;
}
.right {
  flex: 0 1 auto;
  display:flex;
  flex-direction: column;
  background: green;
  padding: 4px;
}

.right-top-wrapper {
  flex: 0 0 auto;
  overflow-x: auto;
  overflow-y: auto;
  background: blue;
}

.right-top-content {
  margin: 4px;
  flex: auto;
  background: pink;
}

.right-bottom {
  flex: 0 0 0;
  background: yellow;
  margin: 4px;
}

If you want the main to be a fixed width, adjust that accordingly too.

A: Your blue container (.right-top-wrapper) is set to flex: 1 1 0. This breaks down to:

*

*flex-grow: 1

*flex-shrink: 1

*flex-basis: 0
It's the flex-grow: 1 that's forcing the element to consume all available space in the column, leaving the content (pink box) behind, and pinning the yellow "Right bottom" box to the bottom.
You wrote:

I have tried .right-top-wrapper { flex: 0 1 0; } but then it shrinks to nothing (a consequence of overflow-y: scroll or auto, which I have to have to allow large "Right top content").

No, it's a consequence of flex-basis: 0, which translates to height: 0. Without flex-grow: 1 to expand the height like before, the box has a zero height.
Try this instead: .right-top-wrapper { flex: 0 1 auto; }
Now flex-grow is disabled and the box takes the height of the content.
You also need to release the fixed height on the pink box so it expands along with the blue container.
.right-top-content {
     /* height: 100px */
     min-height: 100px; /* new */
}

revised fiddle (little content)
revised fiddle (lots of content)


text:
Q: AJAX: responseXML returning null however ResponseText returns the XML as a string I'm trying to retrieve an XML file from the server-side (PHP) and subsequently send it to the client-side (JavaScript). The issue i'm having is that the responseXML keeps returning null. However, if i change it to responseText it returns the xml file in a string so this tells me that the .js can receive the xml file from the server side.

cart.js
if (window.XMLHttpRequest)
{
  xHRObject = new XMLHttpRequest();
}

else if (window.ActiveXObject)
{
  xHRObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function loadDoc()
{

  xHRObject.open("GET", "cart.php", true);

  xHRObject.onreadystatechange = function()
  {
  if (xHRObject.readyState == 4 && xHRObject.status == 200)
  {
    myFunction(xHRObject);
  }

  }

  xHRObject.send();
}

function myFunction(xml)
{
  var xmlDoc = xml.responseXML;

  alert(xmlDoc);

 ...

}

cart.php
<?php

 header('Content-Type: text/xml');

 $xmlFile = "cart.xml";

  $doc = new DOMDocument();
  $doc->load($xmlFile);

  $strXml = $doc->saveXML();
  echo $strXml;

?>

Hope someone here could help me out as i've search this problem online but couldn't find a solution. I've also tried parsing the responseText:
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(XHR.responseText, "text/xml");

but it can never return the nodes.
Any help will be appreciated!
Thank you
Solution: had blank line at the top of php file

A: The problem was that php file had a blank line at the top. Had to remove it so no extra (unnecessary) content will be printed out.


text:
Q: Decomposition of matrix How we decompose or break matrix $A$ in the following form.
$$A = \begin{pmatrix} {a_1}^2 & a_1a_2 & ... a_1a_n \\
 a_2a_1 & {a_2}^2 & ... a_2a_n \\.... \\
 a_na_1 & a_na_2 & ... {a_n}^2 \end{pmatrix} = \begin{pmatrix} a_1 & a_1 & ... a_1 \\
 a_2 & a_2 & ... a_2 \\.... \\
 a_n & a_n & ... a_n\end{pmatrix}×\begin{pmatrix} a_1 & a_1 & ... a_1 \\
 a_2 & a_2 & ... a_2 \\.... \\
 a_n & a_n & ... a_n\end{pmatrix}$$
My Attempt:
Taking RHS = $$\begin{pmatrix} a_1 & a_1 & ... a_1 \\
 a_2 & a_2 & ... a_2 \\.... \\
 a_n & a_n & ... a_n\end{pmatrix}×\begin{pmatrix} a_1 & a_1 & ... a_1 \\
 a_2 & a_2 & ... a_2 \\.... \\
 a_n & a_n & ... a_n\end{pmatrix} = \begin{pmatrix} {a_1}^2+a_1a_2+...+a_1a_n & {a_1}^2+a_1a_2+...+a_1a_n & ... {a_1}^2+a_1a_2+...+a_1a_n \\
 a_2a_1+{a_2}^2+...+a_1a_n & a_2a_1+{a_2}^2+...+a_1a_n & ... a_2a_1+{a_2}^2+...+a_1a_n \\.... \\
 a_na_1+a_na_2+...+{a_n}^2 & a_na_1+a_na_2+...+{a_n}^2 & ... a_na_1+a_na_2+...+{a_n}^2 \end{pmatrix} $$
I couldn't proceed it further. Please help me.

A: The decomposition you post is wrong. A simple counterexample: Let $n=2$, $a_1=1$ and $a_2=0$. We have
$$\begin{pmatrix}a_1 &a_1\\
a_2 & a_2\end{pmatrix}\begin{pmatrix}a_1 &a_1\\
a_2 & a_2\end{pmatrix}=\begin{pmatrix}1 &1\\
0 & 0\end{pmatrix}\begin{pmatrix}1 &1\\
0 & 0\end{pmatrix}=\begin{pmatrix}1 &1\\
0 & 0\end{pmatrix}\neq\begin{pmatrix}1 &0\\
0 & 0\end{pmatrix}=\begin{pmatrix}a_1^2 &a_2\\
a_2a_1 & a_2^2\end{pmatrix}.$$
A correct decomposition is
$$A=\begin{pmatrix} a_1^2 & a_1a_2 & \dots & a_1a_n\\
a_2a_1 & a_2^2 &\dots & a_2a_n\\
\vdots & \vdots & \ddots & \vdots\\
a_na_1 & a_na_2 &\dots & a_n^2\end{pmatrix}=\begin{pmatrix} a_1 & 0 & \dots &0\\
0& a_2 &\dots &0\\
\vdots & \vdots & \ddots & \vdots\\
0& 0 &\dots & a_n\end{pmatrix}\begin{pmatrix} a_1 & a_2 & \dots & a_n\\
a_1 & a_2 &\dots & a_n\\
\vdots & \vdots & \ddots & \vdots\\
a_1 & a_2 &\dots & a_n\end{pmatrix}.$$
To obtain the above decomposition, simply note that all elements in the $j$-th row have a common factor $a_j$, for all $j=1,\dots,n$.
Or noting that all elements on the $j$-th column of $A$ have a common factor $a_j$, which yields
$$A=\begin{pmatrix} a_1^2 & a_1a_2 & \dots & a_1a_n\\
a_2a_1 & a_2^2 &\dots & a_2a_n\\
\vdots & \vdots & \ddots & \vdots\\
a_na_1 & a_na_2 &\dots & a_n^2\end{pmatrix}=\begin{pmatrix} a_1 & a_1 & \dots & a_1\\
a_2 & a_2 &\dots & a_2\\
\vdots & \vdots & \ddots & \vdots\\
a_n & a_n &\dots & a_n\end{pmatrix}\begin{pmatrix} a_1 & 0 & \dots &0\\
0& a_2 &\dots &0\\
\vdots & \vdots & \ddots & \vdots\\
0& 0 &\dots & a_n\end{pmatrix}.$$
In fact, the second decomposition also follows from the first one right away, as $A$ is symmetric, i.e., $A=A^T$.


text:
Q: Is it possible to say that the set $D$ is discrete? Assume that a set $D$ has no accumulation point. Then: Is it possible to say that the set $D$ is discrete?

A: Yes. In fact, it's possible to make a stronger statement: $D$ has no accumulation point if and only if $D$ is both discrete and closed.

A: Supose $D$ has no accumulation point, then for any $x \in D$, there is an $\epsilon > 0$ such that the ball $B(x;\epsilon)$ contains only finitely many points of $D$. Call these points (other than $x$ itself) $x_1, x_2, \ldots, x_n$, then choose
$$
\delta_x = \frac{1}{2}min\{d(x,x_i): 1\leq i\leq n\}
$$
Then $B(x;\delta_x)$ contains exactly one point, namely $x$.
This is true for any point $x \in D$. Hence, $D$ is discrete.


text:
Q: What to do to avoid VBA function executed in the wrong work book I have several excel files that have timer and macros executing. But a big problem is when workbook A's macro is called, while workbook B is active. The macro is executed in the wrong book and failed.

*

*Do I need to put windows().active at the beginning of every function?

*If I have different modules how do I pass this workbook name to all of them?

*This seems excessive and not right. Is there any good solution to this problem?

Looking forward to your answers

A: You are on the right track with this

2.If I have different modules how do I pass this workbook name to all of them

I assume that your macro is using the ActiveWorkbook property, or just using Worksheet properties like Range without qualifying them?
Instead of using ActiveWorkbook use ThisWorkbook. Instead of using Range use ThisWoorkbook.Worksheets(1).Range and so forth. Otherwise the macro will assume that the active worksheet is the one you want.
Sub MyMacro
  Range("A1").Text = "Test"
End Sub

Try
Sub MyMacro(ByVal oWorksheet as Worksheet)
  oWorksheet.Range("A1").Text = "Test"
End Sub

Then pass the worksheet object as a parameter.
You may also find the ThisWorkbook object useful - it is the workbook the macro resides in, or the Application.Caller object, which is the object calling the current macro, for example the Range object if it is a cell formula, or presumably the timer object in your case.

A: If your macros behave the way you described it, they probably depend explicitly or implicitly on
ActiveWorkbook

or
 ActiveSheet

Those kind of dependencies should be avoided, if possible. The macro recorder produces such code, you should change it immediately whenever you have recorded a macro.
For example, if you have some code like
s = Range("A1").Value

Excel implicitly changes that to
s = ActiveSheet.Range("A1").Value

One can avoid that by accessing all cells, ranges, workbook parts etc. by explicitly using the right sheet or workbook object:
Dim sh as Worksheet
Set sh = .... ' Initialize sh the first time where the sheet is created or loaded

'later on:

s = sh.Range("A1").Value

By using a parameters of the form
sh as Worksheet, wb as workbook

for your subs and functions, you can pass the right sheet and workbook between modules, which answers your second question. And if you need access to the workbook where your macro resides, use ThisWorkbook.

A: I'd go one further... make sure your code doesn't have
Selection
or
ActiveCell
objects within them. You would need to rewrite these using the Range object.


text:
Q: Execution Timed Out (12000 ms): How can I optimize this simple kata to run faster? I'm practicing my coding chops after a long break and ran into this kata on CodeWars
With an input of numbers in an array, return the sums of its parts. So for example:
def parts_sums(ls)
 sums = []
  until ls.size == 0
    sums << ls.inject(:+)
    ls.shift
  end
  sums << 0
end

######### INPUT #######
parts_sums([0, 1, 3, 6, 10])

######### EXPECTED OUTPUT ######
[20, 20, 19, 16, 10, 0]

0 + 1 + 3 + 6 + 10 = 20
1 + 6 + 3 + 10 = 20
3 + 6 + 10 = 19
6 + 10 = 16
10 = 10
0 = 0

My solution solves the kata, however once I reach arrays of around 30,000+ my solution takes too long to solve.
So my question is to the community, how would I even attempt to make this go faster. I know that recursion is usually slow, and that for loops and its variants are usually sufficient to get the job done. What happens when that fails? What are some things to try to make my code above faster?
I'm looking for some advice and some examples if anyone has any. Appreciate the input. Thanks.

A: def parts_sums(ls)
  ls.each_with_object([ls.sum]) { |n,arr| arr << arr.last - n }
end

parts_sums([0, 1, 3, 6, 10])
  #=> [20, 20, 19, 16, 10, 0]

A: The issue with the code is that you are performing an inject on every iteration of your loop, which is unnecessarily slow.
You only need to sum the elements of the array once, outside of any loop. Once you have that sum, you can iterate through the elements of the array and perform a constant time subtraction from the current sum and push it into the sums array.
def part_sums(ls)
  sum = ls.inject(:+)
  sums = [sum]
  ls.each do |val|
    sum -= val
    sums << sum
  end
  sums
end

There is also no need to shift, if you iterate through the array with the each iterator or keep a counter and use a while loop.

A: This version of the function runs much faster:
def parts_sums_2(ls)
 sums = []
 last_sum = 0
 (ls.length - 1).downto(0).each do |i|
   last_sum += ls[i]
   sums.prepend last_sum
 end
 sums + [0]
end

The key here is going backwards through the array - starting with the smallest sum (only the last element). Each subsequent step moves one index towards the beginning, and adds that value to the previous sum.
Since the problem statement requires you to shift each step, your result must have the largest sums at the beginning, even though these are the last ones to be computed. This is why my code uses prepend rather than push.
This is O(N) time complexity instead of O(N^2), which is an order of magnitude difference.
With 100_000 inputs, your original function took 7.040443 seconds, while mine here took 0.000008 seconds
Also in general you should try to avoid mutating the input to your methods (as you were doing with shift).


text:
Q: Questions on topological manifolds
*

*Does the dimension of a manifold depend on the topology? That is, can I endow a set with a topology $T$ and get an $n$-dimensional manifold, and endow the exact same set with another toplogy $T'$ and get an $m$-dimensional manifold, with $n\neq m$?

*Can a curve like this:
$\hskip1.3in$
be given the topology of a 1-manifold? Or a curve like this cannot be a manifold with any topology?

A: (1) Yes, the dimension of the manifold depends on the topology.  A $3$-manifold has neighborhoods which are homeomorphic to $\mathbb{R}^3$, a $2$-manifold has open neighborhoods homeomorphic to $\mathbb{R}^2$, and so forth.
As Dylan Moreland points out in the comments, $\mathbb{R}$ and $\mathbb{R}^2$ both have the same cardinality.  We may regard them as in bijection, therefore as two representations of the same uncountable set.  When we endow them with two different topologies, we have two manifolds of different dimension.
For another example, consider $\mathbb{Z}$ and $\mathbb{Q}$.  Again, they are in bijection, but while $\mathbb{Z}$ (with its discrete topology) is a $0$-dimensional manifold, $\mathbb{Q}$ with the topology inherited from its inclusion in $\mathbb{R}$ is not a manifold at all.
(2) As a set, certainly; the curve can be put in bijection with $\mathbb{R}^2$ and given the same topology.  If you are really asking whether the curve is a $1$-dimensional manifold, then the answer is "no."  To be a manifold, about every point on the curve there must be an open neighborhood homeomorphic to $\mathbb{R}$.  Observe that no connected neighborhood of its point of self-intersection is homeomorphic to $\mathbb{R}$ since removing any point of $\mathbb{R}$ results in two open components, but removing the point of self-intersection from a small connected neighborhood of the point of self-intersection results in four open components.

Here are some more general comments.  You're conflating two levels of abstraction here: the basic machinery of point-set topology and the foundations of manifold theory.  Manifold theory is more concrete than point-set topology, in the sense that all of manifold theory deals with very specific types of topological spaces.  To admit the possibility of having the structure of a topological manifold, the topology of a set must already be Hausdorff, paracompact, and second-countable. This rules out entire classes of topological spaces, and even rules out many metric spaces.
Meanwhile, most of the topological spaces we encounter frequently are built from uncountable sets.  It may be an understatement when I say that there are many, many topologies you can put on an uncountable set.  Only a tiny, tiny fraction of them could have the faintest hope of ever possibly sitting under a manifold structure.  So it seems strange to try to think about a manifold structure in terms of the topology of the underlying set; they're in different layers of abstraction.
Maybe a computing analogy would help. Working with a topology on a set is like designing a processor.  Working with a manifold is like programming software.  To program software, you need a working processor, but once your processor works, you generally forget about the processor design, unless it becomes relevant, and just deal with the programming language.

Edited in response to comments by Henry T. Horton and Mariano Suarez-Alvarez.


text:
Q: My directory name is bugged and i dont know what to do I have made a script that buld runs and installs SteamCMD server but I noticed very weird problem that is stoping me in further development.
My code:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
docker pull yzere/steamcmd:latest
docker run -it -d --name=steamcmd yzere/steamcmd bash
docker exec -it steamcmd bash
/bin/bash ./steamcmd.sh +login anonymous +app_update 343050 +quit
curl -o ~/run_dedicated_server.sh https://github.com/yzere/steamcmd/blob/master/run_dedicated_server.sh
chmod u+x ~/run_dedicated_server.sh
mkdir ~/.klei/
mkdir ~/.klei/DoNotStarveTogether/
echo "Now upload MyDediServer.zip and unpack in .klei/DoNotStarveTogether/, after this again run ~/run_dedicated_server.sh"

and beside problem with docker instalation, after i run ls on my machine there was this folder:
image
with the name of '.klei'$'\r' instead of intended .klei
It also makes terminal go crazy when i tried to enter this directory.
I really look for some kind of explaination or solution to this.
Also error message when i run this script was this
E: Invalid operation update
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'docker-ce' has no installation candidate
E: Unable to locate package docker-ce-cli
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io
   '
E: Couldn't find any package by regex 'containerd.io
   '
./server.sh: line 3: docker: command not found
./server.sh: line 4: docker: command not found
./server.sh: line 5: docker: command not found
/bin/bash: ./steamcmd.sh: No such file or directory
curl: (3) URL using bad/illegal format or missing URL
chmod: cannot access '/home/yzere12/run_dedicated_server.sh'$'\r': No such file or directory
mkdir: cannot create directory '/home/yzere12/.klei\r': File exists
mkdir: cannot create directory '/home/yzere12/.klei/DoNotStarveTogether\r': No such file or directory
Now upload MyDediServer.zip and unpack in .klei/DoNotStarveTogether/, after this again run ~/run_dedicated_server.sh

I run linux wersion of Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64


text:
Q: Calculate conditional average on disjoint cells I would like to know if libreoffice calc has the functionality to calculate an conditional average on disjoint cells. An example would be: Calculate the average for every second cell in Row1 if Row2 does not contain an x.
     | C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9
--------------------------------------------------
Row1 |  1 |  2 |  3 |  4 |  5 |  6 |  7 |  8 |  9
Row2 |  x |  x |    |    |    |  x |  x |    |

Beginning at C1 the result should be: mean(3, 5, 9) = 5.666666
Beginning at C2 the result should be: mean(4, 8) = 6
Although there is a solution using IF statements for every cell I would like to know if there is a more convinient way to do it. I already searched for a solution like LOOKUP or COUNTIF but all those functions need a consecutive range as input for the data and condition.
I hope someone can help.
[EDIT]: Answer
I finally found a solution by myself. The asnwer is to use the SUMPRODUCT function in addition to another row or the MOD function:
=SUMPRODUCT(MOD(COLUMN(C1:C9), 2)=0, C1Row2:C9Row2<>"x", C1Row1:C9Row1)/SUMPRODUCT(MOD(COLUMN(C1:C9), 2)=0, C1Row2:C9Row2<>"x")

A: I finally found a solution by myself. The asnwer is to use the SUMPRODUCT function in addition to another row or the MOD function:
=SUMPRODUCT(MOD(COLUMN(C1:C9), 2)=0, C1Row2:C9Row2<>"x", C1Row1:C9Row1)/SUMPRODUCT(MOD(COLUMN(C1:C9), 2)=0, C1Row2:C9Row2<>"x")

A: I don't have immediate access to LibreOffice Calc.
You can do this in Microsoft Excel by using the AVERAGEIFS function and a "helper row".
I've chosen Row 42.  In cell A42, enter =MOD(COLUMN(), 2), then drag/fill that out to I42
(i.e., far enough to correspond to all your data; in your example, you show nine columns).
This should give you an alternating sequence of 1, 0, 1, 0, …
Then the answer that you want is
=AVERAGEIFS(A1:I1, A2:I2, "<>x", A42:I42, 1)

i.e., the average of the values within A1:I1 for which the value in Row 2 is not "x"
and the value in Row 42 is 1.
You said "if Row2 does not contain an x".  I interpreted that to mean "if the corresponding value
in Row 2 is not x".  If you mean "if the corresponding value in Row 2 does not contain an x"
(so words like "excel" and "fox" would also invalidate the corresponding value in Row 1),
you'll probably need a second "helper row" to handle that.


text:
Q: search and replace between two files -post#2 I need to replace a variable in one file with information/regex found in another file. For example, I need to grab the first string/variable (that starts with MSTRG) from each row in file1:
MSTRG.5734  MSTRG.5734  509 -4  0   -14 0   0
MSTRG.19266 MSTRG.19266 842 -4  0   -12 0   0
MSTRG.26588 MSTRG.26588 196 5   0   12  0   0

and use this to search in file2 that will look something like this:
Chr1    StringTie   transcript  24039360    24041181    1000    -   .   gene_id "MSTRG.5734"; transcript_id "MSTRG.5734.1";
Chr1    StringTie   transcript  24039810    24040595    1000    -   .   gene_id "MSTRG.5734"; transcript_id "Transcript:AT1G64700.1"; ref_gene_id "Gene:AT1G64700"
Chr1    StringTie   exon    24040560    24041181    1000    -   .   gene_id "MSTRG.19266"; transcript_id "MSTRG.19266.1"; exon_number "2";
Chr1    StringTie   exon    24040560    24041181    1000    -   .   gene_id "MSTRG.26588"; transcript_id "MSTRG.26588.1"; exon_number "2";
Chr1    StringTie   transcript  24039810    24040595    1000    -   .   gene_id "MSTRG.26588"; transcript_id "Transcript:AT5G41000.1"; ref_gene_id "Gene:AT5G41000";

Ideally when e.g. MSTRG.5734 is found on a line in file2 that also contains the string e.g. Gene:AT1G64700, it will grab the information Gene:AT1G64700 and replace MSTRG.5734 in file1. So, every MSTRG on each row in file1 is unique and it will theoretically match a unique Gene in file2. If it does not match a Gene then I need the original row in file1 to be maintained.
File1 output should then look like:
    Gene:AT1G64700  MSTRG.5734  509 -4  0   -14 0   0
    MSTRG.19266 MSTRG.19266 842 -4  0   -12 0   0
    Gene:AT5G41000  MSTRG.26588 196 5   0   12  0   0

My current perl code is:
use strict;
use warnings;
use vars qw($outfile @id $mstrg $gene);

open(SEARCH, $ARGV[0]) or die "Couldn't open $ARGV[0]: $!";
open(FILE, $ARGV[1]) or die "Couldn't open $ARGV[1]: $!";
$outfile = "testout.txt";
open (OUT, ">$outfile") || die "Can't open $outfile for creation: $!\n";

my %mstrg;

while (<SEARCH>) {
chomp;
if (/^MSTRG/) {
    chomp $_;
    @id = split (/\t/, $_);
        $mstrg{$id[1]}.="$id[1]";
 }
}
while (<FILE>) # {@ffn=<FILE>};
{
chomp ($gene=$_);
    if ($mstrg =~ /$gene/) {
    print OUT "$id[1]\t$id[2]";}
    else {
        #print OUT "$_\n";
            }
next;
        }

close FILE;

This is unfortunately where I get stuck and not sure how to proceed?
Thanks for any help given, appreciated and apologies for the previous post where I did not include any code to those that saw.

A: I would do this somewhat like:
use 5.014;               #needed min 5.014 because the /r modifier
use warnings;
use Path::Tiny '0.077';  #added the min. req. version

my $file1='file1.txt';
my $file2='file2.txt';

my %mstmap = map { split /\s+/, s/.*?gene_id\s*"\s*(MSTRG\.\d+).*ref_gene_id\s*"\s*(Gene:\w+)".*/$1 $2/r }
             grep { /ref_gene_id.*Gene:/ } path($file2)->lines({chomp => 1});
path($file1)->edit_lines( sub { s/^(MSTRG\.\d+)/exists($mstmap{$1}) ? $mstmap{$1} : $1/e });

for your input files produces
Gene:AT1G64700  MSTRG.5734  509 -4  0   -14 0   0
MSTRG.19266 MSTRG.19266 842 -4  0   -12 0   0
Gene:AT5G41000 MSTRG.26588 196 5   0   12  0   0

It create a hash for the pairs: MSTRG.number => Gene:String (from the file2), and using the Path::Tiny module editing fucntion doing the replaces in the file1.
After @Borodin comments the above could be reduced to:
use 5.014;
use warnings;
use Path::Tiny '0.077';

my $file1='f1';
my $file2='f2';

my %mstmap = map {
    /.*?gene_id\s*"\s*(MSTRG\.\d+).*ref_gene_id\s*"\s*(Gene:\w+).*/
} path($file2)->lines({chomp => 1});
path($file1)->edit_lines( sub { s/^(MSTRG\.\d+)/exists($mstmap{$1}) ? $mstmap{$1} : $1/e });

A: There's no need to write impregnable code to achieve the result you want
This program reads through $file2 building hash %mstrg from all the lines that contain both an MSTRG. and a Gene: string. It then creates a regex in $re that will match any one of the MSTR. strings found
$file1 is opened, and that regex is used to replace any of the hash keys with the corresponding hash value it appears at the start of the line. The line is then printed
It isn't clear whether the first two fields of file1.txt are always the same, but I've opted to alter only the first field
I've used the autodie pragma to avoid having to explicitly check for success of any file IO operations
The program prints the output to STDOUT, so you can redirect it wherever you like on the command line
use strict;
use warnings 'all';
use autodie;

my ( $file1, $file2 ) = @ARGV;

my %mstrg;

{
    open my $fh, '<', $file2;

    while ( <$fh> ) {
        $mstrg{$1} = $2 if /"(MSTRG.\d+)".*"(Gene:\w+)"/;
    }
}

my $re = join '|', sort { length $b <=> length $a } keys %mstrg;

open my $fh, '<', $file1;

while ( <$fh> ) {
    s/^($re)\b/$mstrg{$1}/;
    print;
}

output
Gene:AT1G64700  MSTRG.5734  509 -4  0   -14 0   0
MSTRG.19266 MSTRG.19266 842 -4  0   -12 0   0
Gene:AT5G41000 MSTRG.26588 196 5   0   12  0   0


text:
Q: Why can't I ssh using a port other than 22 with macOS 10.15.4? I'm trying to ssh to a machine that opens the port 8012 for ssh as opposed to port 22. When I ssh at the command line (ssh -p 8012 username@host), nothing happens. The -vvv option gives no pertinent information other than "trying to connect".
I can do ssh ssh://new@sdf.org (on standard port 22) without problems.
Further, on this Mac I have a VM running Debian. Within this VM I can ssh on the machine with the non-standard port 8012 without problems.
I also have a separate Windows machine where I also have no problems doing what I described.
Edit: output of ssh -vvv ...:
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/[username]/.ssh/config
debug1: /Users/[username]/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to [destination] port 8012.

And then it gets stuck there.
Output of cat ~/.ssh/config:
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Uncommented lines of the output of cat /etc/ssh/ssh_config:
Host *
    SendEnv LANG LC_*

A: It appears my issue is specifically tied to a recent update of MacOS. The answer was found here: https://mjtsai.com/blog/2020/03/31/macos-10-15-4-broke-ssh/. Specifying the IP address of the server rather than its name resolved my issue.


text:
Q: Multiple video element pointing to the same useRef() [React] Is it possible to use the same videoRef on 2 elements?
Intended outcome: displaying 2 videos in 2 different <video>, pointing to the same videoRef on the same page concurrently.
const videoRef = useRef();
const videoRef2 = useRef();

return (
  <div>
    {/* ... a video (videoRef) at top */}
    <video
      videoRef={videoRef}
    />
    {/* ... somehere else on the same page, the same video (videoRef) */}
    <video
      videoRef={videoRef}
    />
    {/* ... another video (videoRef2) */}
    <video
      videoRef={videoRef2}
    />
  </div>
);

A: I'm not sure that is a possible thing to do
but there's a good way to handle this
const videoRefs = useRef([React.createRef(), React.createRef()]);

<video
   ref={videoRefs.current[0]}
/>
....
<video
   ref={videoRefs.current[1]}
/>

Or may be as this:
const videoRefs = useRef([]);

<video
  ref = {el => videoRefs.current[0] = el}
/>
....
<video
  ref = {el => videoRefs.current[1] = el}
/>

check this out too

A: *

*No. You can't use a reference to 2 elements because each element which is rendered in the real DOM is unique. videoRef will refer to second <video>


text:
Q: How to create coordinate system and locate points in R? How can I create quadrant I (+,+) of coordinate system in R and add points in it?

A: Do you mean just a standard plot as this one:
points_plot<-data.frame(x=c(3,7,8),y=c(9,2,6))

plot(points_plot,pch=20)


text:
Q: Cannot resolve symbol 'JwtConfigurer' IntellijDEA (windows10)
Как можно видеть, они лежат в одном модуле (слева). Почему идея их не видит?
До этого все работало нормально - единственное изменение, на котором все сломалось - переключилась на другую ветку. Что самое невероятное, приложение нормально запускается на сервере томкат и исправно работает

A: Вот что решило мою проблему:

Похоже, идея иногда устает


text:
Q: HTTP - Status Code I'm using Spring Boot and controllers I'm feeling difficulty to treat some errors, for this reason I have some questions about the most appropriate status for each of the following situation:

*

*PUT Object no Id

Put the URL localhost:8080/users/1 with a JSON without the Id attribute.

*PUT Object with different parameter Id

Put the URL localhost:8080/users/1 with a JSON with Id 2, ie, different from what was passed in the parameter.

*GET with invalid parameter

GET on the URL localhost:8080/users/search?sex=ABC, or an invalid sex for the system (the correct would be sex = male or female?).

*JSON POST with id

Performing a POST in order to persist the data (create) but with id.

A: Case 1. Id is in the uri : no error
Case 3. "400 Bad request" is acceptable. (client should not retry the exact same request)
Cases 2. and 4. Just ignore the Id from the body and return 200 or return a "400 Bad Request"
Note that the id shouldn't be seen as an attribute of the resource: it is a part of the resource identifier.


text:
Q: Access Rails session in create-react-app side I am following a tutorial which use a custom Rails app with create-react-app. Rails app running on localhost:3000 and create-react-app running on localhost:3001. Everything works as expected but I have one question, is there anyway to access Rails session in create-react-app side? Currently when I want to develop I have to build my app then go to Rails side to check the result. If I want to build my app for every change the process is too slow. The problem is session[:user_id] is not accessible in React side. As I said it is a tutorial and I have never have experience with two servers running on different port. I have cors-rack rails and I have this setting in my Initializer :
session_strore.rb:
 if Rails.env === 'production'
  Rails.application.config.session_store :cookie_store, key: '_calendar-app', domain: :all
 else
  Rails.application.config.session_store :cookie_store, key: '_calendar-app'

It looks like the cookies sets for React side but session[:user_id] is not accessible. I just want to know is there any way to access session[:user_id] inReact` side?

A: Why do you need to access session[:user_id]? All rails cookies are encrypted and you can't just take it from cookie store.
About long build time - why are you need to make full build for every change?


text: Q: Extending OSM database with new data I want to add a new table inside my OSM database with extra data for every restaurant, and then when retrieving the places join the table by the "osm_id", is this possible and if yes, any tips or instructions?


text:
Q: How do I set meta tags using php in a Magento module? This doesn't work in my .phtml file.
$head = $this->getLayout()->getBlock('head');
$head->setTitle("title blah");
$head->setDescription("description goes here");
$head->setKeywords("apples bananas coconuts");

A: I believe you are going to want to put that code into your controller, not your view files.


text:
Q: Uinitialized constant BaseController error when using admin namespace I have an admin namespace as such:
  namespace :admin do
    resources :users
    resources :base
  end

With the following directory structure:
/app/controllers/
        + admin
            - base_controller.rb
            - users_controller.rb
        - users_controller.rb
        - application_controller.rb

I have to wrap admin/users_conroller.rb in a module Admin end, otherwise I get an Uninitialized constant BaseController error:
class Admin::BaseController < ApplicationController
end

# Works fine
module Admin
  class UsersController < BaseController
  end
end

# Breaks with error
class Admin::UsersController < BaseController
end

Any idea why this is happening? Using Rails 3.2.

A: Namespaces map to directories, underscored filenames are camelcased for class names.
class Some::DeeplyNested::BaseActionsController < ApplicationController

needs to be in app/controllers/some/deeply_nested/base_actions_controller.rb for rails to find it.
In your code, there is no app/controllers/base_controller.rb, so BaseController in
class Admin::UsersController < BaseController

points to no class Rails knows about. You need to give it the admin namespace (as your class definition for BaseController also has)
class Admin::UsersController < Admin::BaseController
end

The above and your working code from your Question are one in the same
module Admin
  class UsersController < BaseController
  end
end


text:
Q: Time-series data: How to code t-1 and t+1 based on value of specific variable in t0? I am interested in learning how a specific factor such as foreign investments behaves 5 years before and after change, e.g. outbreak of civil war.
This is the structure of my data (the factor is not included here):
year country   change  time
2001 A         0       ? (-1)
2002 A         1       0
2003 A         0       ? (+1)
2004 A         0       ? (+2)
2002 B         0       ? (-2)
2003 B         0       ? (-1)
2004 B         1       0
...

I am seeking to replace the question marks by the respective values in brackets, e.g., "-1" for the year prior to change (t-1) and "+1" for the year following change (t+1). The presence of change is coded with 1.
How would you do this? I am grateful for any suggestions.

A: > dat <- read.table(text="year country   change  time
+ 2001 A         0       ?(-1)
+ 2002 A         1       0
+ 2003 A         0       ?(+1)
+ 2004 A         0       ?(+2)
+ 2002 B         0       ?(-2)
+ 2003 B         0       ?(-1)
+ 2004 B         1       0
+ ", header=TRUE)
> with(dat, tapply(change, country,
                              function(x) seq(length(x))-which(x==1) ) )
$A
[1] -1  0  1  2

$B
[1] -2 -1  0

> dat$time <-unlist( with(dat, tapply(change, country,
                              function(x) seq(length(x))-which(x==1) ) ) )
> dat
  year country change time
1 2001       A      0   -1
2 2002       A      1    0
3 2003       A      0    1
4 2004       A      0    2
5 2002       B      0   -2
6 2003       B      0   -1
7 2004       B      1    0
>

Slightly less complex would be to use ave instead of unlist(tapply(...))
> dat$time <- with(dat, ave(change, country, FUN=function(x) seq(length(x))-which(x==1) ) )
> dat
  year country change time
1 2001       A      0   -1
2 2002       A      1    0
3 2003       A      0    1
4 2004       A      0    2
5 2002       B      0   -2
6 2003       B      0   -1
7 2004       B      1    0