Posts

c++ - std::bad_alloc when inserting into std::unordered_map? -

i'm getting std::bad_alloc following code: typedef std::unordered_map<chash, block_extended_info> map_type; map_type m_foo; // transgressor: auto r = m_foo.insert(map_type::value_type(id, bei)); it happens of time while running test cases use method containing line, , other times doesn't. had changed code use m_foo[id] = bei , caused stop happening 1 compilation, when recompiled again failed, changed above, continued fail. issue deeper that. i sure it's not matter of running out of memory since have top running while test cases running , doesn't anywhere near filling memory. what may causing std::bad_alloc? in details of chash , block_extended_info may causing this? objects of types copied , passed around on place in other parts of code , doesn't cause issues. here's definition of chash : class chash { char data[32]; }; and following required define block_extended_info : class csignature { chash c, r; }; enum foob { /* ... ...

sublimetext2 - Replace characters by key binding in sublime text 2 -

how write key binding replace specific character one? for example want replace "[" , "]" empty string "". unfortunately, make custom key binding need write plugin in python finding , replacing, there no built-in commands doing so. however, want accomplished using find -> replace... dialog. make sure regular expressions button selected, put \[|\] in find what: box, , nothing in replace with: box (it's best put cursor in there , delete everything, in case there invisible characters such spaces or tabs there). hit replace replace characters 1 @ time, or replace all replace of them in 1 go.

java - Change property file located in src/test/resources -

i'm exploring apache common configuration , want make test read/write properties from/to xml file located in src/test/resources test. far, i'm reading no problems cannot write file. if change location of file scr/test/resources location in file system (example: c:/test), works fine. can please me ? edit here had tried far: @test public void test() throws configurationexception { //first data.xml located in src/test/resources xmlconfiguration config = new xmlconfiguration("data.xml"); list<object> rows = config.getlist("user.username"); system.out.println(rows); //this not working config.setproperty("user.username", "fromtest"); config.save(); // second data.xml in different location xmlconfiguration config = new xmlconfiguration("c:/temp/data.xml"); list<object> rows = config.getlist("user.username"); system.out.println(rows); //th...

r - Unwanted rows in data.frame -

i want write function checks number of files name id .csv , return number of rows no na s. here wrote: complete <- function(directory, id) { setwd(directory) my_list <- list.files(getwd(), pattern="*.csv", full.names=true) my_id <- numeric() my_output<-data.frame() my_count<-numeric() for(integer in id){ my_data <- read.csv(my_list[integer]) my_subset <- subset(my_data, sulfate !=0 & nitrate !=0) my_count[integer]<-length(my_subset[[1]]) my_id[integer] <- integer } my_output<-cbind(my_id, my_count) my_output } complete("/home/jpasquier/téléchargements/specdata", c(1,3)) but here result: > complete("/home/jpasquier/téléchargements/specdata", c(1,3)) my_id my_count [1,] 1 117 [2,] na na [3,] 3 243 so don't understand why there unwanted row numbe...

Replacing entire string when a single word is in the string R -

i wondering if had come across solution problem when cleaning data in r. idea have list of strings example: strings = c("hello world", "goodbye all", "help appreciated", "hello sam") then go through list of strings , whenever word found entire string replaced. therefore if looking word "hello" replaced "math" so output looking be: "math", "goodbye all", "help appreciated", "math". any or ideas appreciated. just use grepl : strings = c("hello world", "goodbye all", "help appreciated", "hello sam") > strings[grepl("hello",strings)] <- "math" > strings [1] "math" "goodbye all" "help appreciated" "math"

c# - Static field initialization order with partial classes -

is there way force static field initialization order in partial classes? let's in helloworld1.cs have: partial class helloworld { static readonly string[] = new[] { "hello world" }; } elsewhere in helloworld2.cs have: partial class helloworld { static readonly string b = a[0]; } if initialized before b fine if b initialized before throws an. healthy way use static constructor i'm curious if there's way force or predict initialization order when fields classes in different files of same partial class. when fields present in same file, textual order defines execution of initialization: 10.5.5.1 variable initializers - static field initialization the static field variable initializers of class correspond sequence of assignments executed in textual order in appear in class declaration . if static constructor (§10.12) exists in class, execution of static field initializers occurs prior executing static constructor. otherwise, static ...

php - Using Goutte with Symfony2 in Controller -

i'm trying scrape page , i'm not familiar php frameworks, i've been trying learn symfony2. have , running, , i'm trying use goutte. it's installed in vendor folder, , have bundle i'm using scraping project. question is, practice scraping controller ? , how? have searched forever , cannot figure out how use goutte bundle, since it's buried deep withing file structure. <?php namespace ontf\scraperbundle\controller; use symfony\bundle\frameworkbundle\controller\controller; use goutte\client; class thingcontroller extends controller { public function somethingaction($something) { $client = new client(); $crawler = $client->request('get', 'http://www.symfony.com/blog/'); echo $crawler->text(); return $this->render('scraperbundle:thing:index.html.twig'); // return $this->render('scraperbundle:thing:index.html.twig', array( // 'something' => $something // ...