Posts

Showing posts from March, 2014

python - How do I to turn my .tar.gz file into a file-like object for shutil.copyfileobj? -

my goal extract file out of .tar.gz file without extracting out sub directories precede desired file. trying module method off question . asked question of own seemed answer thought work didn't work fully. in short, shutil.copyfileobj isn't copying contents of file. my code now: import os import shutil import tarfile import gzip tarfile.open('rtlog_20150425t152948.gz', 'r:*') tar: member in tar.getmembers(): filename = os.path.basename(member.name) if not filename: continue source = tar.fileobj target = open('out', "wb") shutil.copyfileobj(source, target) upon running code file out created however, file empty. know file wanted extract does, in fact, have lots of information (approximately 450 kb). print(member.size) returns 1564197 . my attempts solve unsuccessful. print(type(tar.fileobj)) told me tar.fileobj <gzip _io.bufferedreader name='rtlog_20150425t15294

android - Glide + CollapsingToolbarLayout strange behavior -

Image
i'm facing strange behavior when using collapsingtoolbarlayout, toolbar , imageview embedded. here code : <android.support.design.widget.appbarlayout android:id="@+id/bla" android:layout_width="match_parent" android:layout_height="256dp"> <android.support.design.widget.collapsingtoolbarlayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollflags="scroll|exituntilcollapsed"> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionbarsize" android:background="@color/md_white_1000" android:minheight="?attr/actionbarsize" app:layout_collapsemode="pin"

excel vba - How to delete the blank sheets in the given workbook? -

sub deleteemptysheets() dim sh worksheet, wb workbook, c range sh = sheets(wb.sheets) each c in wb.sheets if isempty(sh.usedrange) sh.delete end if next set sh = nothing set wb = nothing set c = nothing end sub question:i tried delete empty sheets, not able exact code. can me in case? thanks. you're not defining wb comes from, , you're not using sh iterate through sheets. i'm assuming want iterate through sheets in active workbook. if so, don't need wb or c . try this: sub deleteemptysheets() dim sh worksheet each sh in activeworkbook.sheets if isempty(sh.usedrange) sh.delete end if next set sh = nothing end sub

java - How do I define the toString in this program. It is supposed to return the super hero based on the favorite color -

i need finish programming assignment in 1 hour. have done of it, cannot understand how complete tostring @ end. program find users favorite super hero. here driver class /* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package superherotester; import java.util.scanner; /** * * @author charters */ public class superherotester { public static superhero asuperhero; /** * program */ public static void main(string[] args) { getdatafromuser(); determinesuperheroidentity(); } public static void getdatafromuser() { scanner keyboard = new scanner(system.in); system.out.println("what first name?"); string firstname = keyboard.nextline(); system.out.println("what last name?"); string lastname = keyboard.nextline(); system.out.println("what supe

php - Error Code: 10944642 Error Message: Error: Inbound SOAP Message - Session Token is missing -

i trying call siebel wsdl, $wsdl = '/home/netvibes/mysw/public/r2/img/isusertrusted.wsdl'; $client = new soapclient($wsdl, array( "trace"=>1, "exceptions"=>0)); $auth = array( 'usernametoken' => 'extapp', 'passwordtext' => 'extapp' ); $header = new soapheader('namespace', 'auth', $auth, false); $client->__setsoapheaders($header); $result = $client->__call('execute_service', array('appthai123zz@zzhotmail.swk') ); i dont know doing wrong, when get, error code: 10944642 error message: error: inbound soap message - session token missing may wrong header. can please help? can share actual message you're sending? error typical when send message missing session token tag. token sent siebel after initial login, prevents having log in each message - reducing au

ios - UITesting How to get a number that's a part of the tabBar section? -

Image
sorry title, didn't know how word question. here's picture help: i want able number "5" next notifications tab variable , struggling so. "notifications" tab button xcuiapplication().tabbars.buttons["notifications"] each uitabbaritem has badgevalue tabbarcontroller?.tabbar.items?[3].badgevalue

python - pandas df.loc[z,x]=y how to improve speed? -

Image
i have identified 1 pandas command timeseries.loc[z, x] = y to responsible of time spent in iteration. , looking better approaches accelerate it. loop covers not 50k elements (and production goal ~250k or more), needs sad 20 seconds. here code (ignore top half, timing helper) def populatetimeseriestable(df, observable, timeseries): """ go through rows of df , put observable timeseries @ correct row (symbol), column (tsmean). """ print "len(df.index)=", len(df.index) # show number of rows global bf, t bf = time.time() # set 'before' t = dict([(i,0) in range(5)]) # fill category timing zeros def t(i): """ timing helper: add passed time category 'i'. set 'before' now. """ global bf, t t[i] = t[i] + (time.time()-bf) bf = time.time() in df.index:

swift - SKScene returns nil when transition method is called -

in little xcode project trying transition scenes when sklabelnode touched presents next scene. reason in scene transition method makes me store optional. , optional returns false. file names correct , no grammatical errors in references causing problem here code. when click sklabelnode ios platform running on recognizes touch app crashes, in console saying optional value returned nil. how resolve problem? thanks import spritekit class gamescene: skscene { let next = skscene(filenamed: "nextscene") override func didmovetoview(view: skview) { let backgroundimage = skspritenode(imagenamed: "ipbg") backgroundimage.size = cgsize(width: self.frame.size.width, height: self.frame.size.height) backgroundimage.position = cgpoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2) addchild(backgroundimage) let playbutton = sklabelnode(fontnamed: "") playbutton.name = "play" playbutton.position = cgpoint(x: se

unix - Pass all parameters of one shell script to another -

i have shell script passing few parameters. test1.sh -a 1 -b 2 -c "one 2 three" inside test1.sh calling shell script in below fashion. test2.sh $* i want pass parameters test2, passed test1 , in same format (with double quotes etc). parameters passed test2 test2.sh -a 1 -b 2 -c 1 2 three doesnt work me. there way around can pass parameters same way passing test1. thanks zabi you need say: test2.sh "$@" refer special parameters : @ expands positional parameters, starting one. when expansion occurs within double quotes, each parameter expands separate word. is, "$@" equivalent "$1" "$2" ... . if double-quoted expansion occurs within word, expansion of first parameter joined beginning part of original word, , expansion of last parameter joined last part of original word. when there no positional parameters, "$@" , $@ expand nothing (i.e., removed). the manual says: &q

c++ - SetWinEvent on a separate Class -

i have little problem qt , here code : sessionsnatcher.h: #ifndef sessionsnatcher_h #define sessionsnatcher_h #include <windows.h> #include <qthread> #include <qtcore> #include <qdebug> class sessionsnatcher : public qthread { public: sessionsnatcher(); ~sessionsnatcher(); void run(); void setpid(int pid); void settid(int tid); int getpid(); int gettid(); hwnd getcoproductcontrol(); private: //hwnd getcoproductcontrol(); void callback sessionsnatcher::handler(hwineventhook hook , dword event , long idchild , long idobject , dword dweventthread , dword dwmseventtime); hwineventhook hook; int pid , tid; }; #endif // sessionsnatcher_h sessionsnatcher.cpp : #include "sessionsnatcher.h" sessionsnatcher::sessionsnatcher() { } sessionsnatcher::~sessionsnatcher() { unhookwinevent(hook); } void callback sessionsnatcher::handler(hwineventhook hook , dword event , long idchild , long idobj

laravel 5 - Issues creating new record with Model::create, Grammar::parameterize() must be of the type array, integer given, -

i have problems create new record of model llista (in english, list), think maybe structure of model::create isn't correct or field of model causing error. so have listcontroller this: llistescontroller.php translations: ( nom_llista equals name_list , llista equals list ) public function store(request $request) { $email = $request->only('email'); $nom_llista = $request->only('nom_llista'); $user = user::where('email', '=',$email)->first(); $userid = $user->id; $llista = llista::create(array( 'nom_llista' => $nom_llista, 'user_id' => $userid) ); } $email , $nom_llista , $user , $userid checked , have correct values, on create fails. error throw laravel doing post request: <!doctype html> <html> <head> <meta name="robots" content="noindex,nofollow" /> <style> /* co

ubuntu - Permission denied (publickey) on Amazon EC2 and can't access server -

i know lot of questions 1 have been asked none of them seem help. i added new users ec2 instance , tried give 1 ssh access. must have messed because can't ssh access account anymore. i'm running ubuntu server , have ssh'd many times today , stopped working. i've found lot of different fixes none of worked. include: using ssh-keygen -r [server ip] chmod 400 on .pem file attaching ebs volume new instance other sites suggests messed permissions on /home folder on server. without access, how can fix these permissions? i've tried many things i'm starting feel i'm making worse. for reference, when try ssh using ssh -i wachtwoord.pem ubuntu@52.30.172.181 -vvv following output: wouters-macbook-pro:aws wouter$ ssh -i wachtwoord.pem ubuntu@52.30.172.181 -vvv openssh_6.9p1, libressl 2.1.8 debug1: reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 20: applying options * debug1: /etc/ssh/ssh_config line 102: applying op

php - Short Solution for SQL Injection Attacks with MySQLI -

i've gotten habit of writing following sort of code: $q = mysqli_query($mysqli,"select * table a='$a', b=$b;"); while ($row = mysqli_fetch_array($q)) { // } where $a string entered user (gotten through $_get ) , $b user-entered integer. obviously code have above vulnerable sql injection attacks, habit rewrite this: $q = mysqli_query($mysqli,"select * table a='".str_replace("'","",$a)."', b=".($b+0).";"); but of course has problems if $a needs have apostrophes (or quotation marks when quotation marks used mark string). recently learned prepared statements in mysqli , started playing around them. wrote following function make easier make calls without having change of code: function safequery($a,$b,$c) { global $mysqli; $q = mysqli_prepare($mysqli,$a); $e = "mysqli_stmt_bind_param(\$q,\$b"; $i = 0; while ($i < count($c)) { $e.=",&

c++ - WinSock: server receives bytes from telnet, not from client -

i trying write client connects server written labmate. can make connection both telnet , own client program using winsock. telnet sends , receives commands fine, client can receive , not send any, despite not receiving error upon starting send() . a snippet of client code: // after connection. // receive message first. recv_size = recv(socket_test, server_resp, strlen(server_resp), null); // check later. server_resp[recv_size] = '\0'; printf(server_resp); // prints initial send server fine. printf("\n"); int bytes; char testmess[100]; // contains test message send. cin >> testmess; bytes = send(socket_test, testmess, strlen(testmess), 0); printf("%d", bytes); // displays right number. i'm wondering difference between send methods between telnet , winsock send() be? have socket configured standard sock_stream type.

ruby - Getting local variable names defined inside a method from outside the method -

is possible in ruby local variables names defined inside method outside method using metaprogramming? def foo var = 100 arr = [1,2] end something foo.local_variables . i need retrieve variable names, not values. why i'm trying find variable names : have class want dynamically generate setters instance variables initialized in "#initialize". in order that, inside "initialize", using instance_variables.each |inst_var_name| define_singleton_method(...) ... this works: each instanced object gets setters singleton methods. however, looking solution read instance variables names outside "initialize" method, in order able use "#define_method" them, , create regular methods , not singleton methods. you can (re)-parse method , inspect s-expr tree. see below proof of concept. can hold of file method defined using method#source_location , read file. there surely room improvement code should started. functional piece of code

c# - How to wrap Datagrid columns in XAML -

Image
i sorry don't know how explain better, want wrap columns in datagrid. i not trying wrap text inside datagrid columns, actual columns of datagrid. i have searched net , have looked through wpf 4.5 adam nathan , due lack of ability describe want , searches ever come text wrapping. , don't faintest idea how approach this. this xaml have datagrid <datagrid name="infocounttextblock" columnwidth="100" grid.row="3" grid.columnspan="4" margin="5" gridlinesvisibility="none" alternationcount="2"> <datagrid.rowstyle> <style targettype="datagridrow"> <setter property="background" value="white"/> <setter property="fontweight" value="normal"/> <style.triggers> <trigg

javascript - Temperature conversion with openweathermap API -

Image
i'm building weather app openweathermap api. app work have problem temperature converter still doesn't work. here html: <div class='valign col s6 text-style'> <div id="icontemp"> <div id="icon"></div> <div id="temp"></div> </div> <div class='divider'></div><br> <div class="text-style-details"> <div class="location"></div> <div id="conditions"></div> <div id="wind"></div> </div> </div> and javascript: <script type="text/javascript"> function toc() { var strin = parseint(temperature); if(isnan(strin)) { alert("not number"); } else { var f = parsefloat(strin); var c = (f -

java - How to Initialize a random number generator within an array to use for a bubble sort -

Image
so coding class, asked create bubble sort method take array generate random numbers array, , sort them via bubble. cant seem array initialize. problem occurs within loop. please? bubble works fine when use pre-initialized numbers. ignore print statements. on line 28, don't declare type int . it's been initialized when array created. use randomnumbers[k] = (int)(math.random()*10); also, used randomnumbers instead of array reason. don't use array capital letter. class name, not variable. (worse yet, it's class exists already .)

visual studio - error LNK1104: cannot open file 'mfc100d.lib' -

i compiled program made vs 2010 in vs 2013, got error. did change tool vs 2010 (v100) , add dependencies (both mfc100d.lib , mfc120d.lib). i set project defaults > use of mfc > use mfc in shared dll. i'm trying looking mfc100d.lib can't find on computer, have mfc100d.dll. do has reference related website, can download mfc100d.lib? this error: error lnk1104: cannot open file 'mfc100d.lib' i use opencv 3.0 , vs ultimate 2013. please me. thank you.

javascript - Google Sheets JSON Error: "Service invoked too many times for one day:" -

i have convert longitude , latitude, useful address (reverse geocode), found script @ [geo scipt][1] i having issue many requests per day, question how can have run once (when data imported ifttt) , not every time open google sheet? function getlat(address) { if (address == '') { logger.log("must provide address"); return; } var geocoder = maps.newgeocoder(); var location; // geocode address , plug lat, lng pair // 2nd , 3rd elements of current range row. location = geocoder.geocode(address); // change cells if geocoder seems have gotten // valid response. if (location.status == 'ok') { lat = location["results"][0]["geometry"]["location"]["lat"]; return lat; } }; function getlon(address) { if (address == '') { logger.log("must provide address"); return; } var geocoder = maps.newgeocoder(); var location; // geocode address ,

xamarin.forms - xamarin forms Slider doesn't distinguish between changing Value in code vs UI change of slider position -

in android slider, progresschangedeventargs has fromuser property. in xamarin forms slider, there seems no way 1 can distinguish between changing slider's value in code vs moving slider knob. because functionality not in ios's uislider? short of embedding native controls, there way achieve functionality? the way achieved sending message when slider touched using messagingcenter. created custom renderers ios , android. in android send messages in starttrackingtouch , stoptrackingtouch seekbar. on ios believe used alltouchevents event fine purposes. another method if value changing model, send event viewmodel rather change value directly (which bad design anyhow if value changing in model , model can access viewmodel.) in case needed know when slider touched because value changing network , needed invalidate network responses period user did not experience slider jumping around.

when i changed orientation portrait to landscape i want layout should change for landscape and video is start from same position in android? -

this whole code media player problem when changed orientation video playing beginning should do.i add "android:configchanges="orientation|screensize|keyboardhidden" in menifest. please help //mediaplayeractivity.java package com.focusmedica.ud_en_acne; import android.app.activity; import android.content.context; import android.content.intent; import android.content.res.configuration; import android.graphics.bitmap; import android.graphics.canvas; import android.graphics.color; import android.graphics.matrix; import android.graphics.paint; import android.graphics.path; import android.media.mediametadataretriever; import android.media.mediaplayer; import android.media.mediaplayer.oncompletionlistener; import android.media.thumbnailutils; import android.net.uri; import android.os.bundle; import android.os.environment; import android.os.handler; import android.util.log; import android.view.motionevent; import android.view.view; import android.view.view.onclicklistene