Posts

Showing posts from July, 2011

javascript - Reading hex data from createReadStream -

my goal make code detect image in stream, , reject upload of not image. so thread talks functionality might need. having problem getting 'hex' values out of stream i have code: imagestream = fs.createreadstream(tmpfile); i this: let filesignature = imagestream.tostring('hex',0,4); so use these magic number signatures: var magic = { jpg: 'ffd8ffe0', png: '89504e47', gif: '47494638' }; in filesignature getting object, while expect first couple of hex values.

Android: Layout always 2/3 screen -

i have many views i'm adding in scroll view (by <include> ). these layouts this: <relativelayout android:id="@+id/one" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constrainttop_totopof="parent" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constraintbottom_tobottomof="parent" android:layout_margintop="10dp" android:layout_marginbottom="10dp" android:layout_marginleft="18dp" android:layout_marginright="18dp" > </relativelayout> this how include layouts fragment layout: <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent"

scala - How to manually throw HTTP 404 Not Found exception in spray/akka? -

in repository function, i'm reading user, updating user: def update(u: user): future[int] = { this.read(u.id).flatmap { case some(existinguser) => db.run( usertable .filter(_.id === user.id) .update(user.copy(createddate = existinguser.createddate))) //case none => throw new notfoundexception(); // exception exist in spray/akka? } } i'd throw sort of exception here when user not found, spray/akka know exception means return http 404 not found. does spray/akka contain sort of notfoundexception can manually throw? you can throw exception , configure exception handler convert exception 404 response.

android - How to enable and disable switchCompat accrodingly to database status? -

i have app in have listview data stored in sqlite database. listview contain switchcompat when enable switch @ index of listview setting status "0" , when disable item setting "1". when status set "0" enable swicth , when status set toi "1" disable switch. pls help. code:- listviewholder.switchcompat.setoncheckedchangelistener(null); boolean ischeck; ischeck = !liststorage.get(position).getstatus().equalsignorecase("0"); listviewholder.switchcompat.setchecked(ischeck); listviewholder.switchcompat.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(final compoundbutton buttonview, final boolean ischecked) { if (ischecked) { new alertdialog.builder(mcontext, r.style.appcompatalertdialogstyle).settitle("warning").setmessage("you want whitelist application?").setpositivebutton("yes&quo

body_filter_by_lua_block nginx lua -

the code below nginx lua: body_filter_by_lua_block { function check_access_file(file) local fh = io.open(file,'rb') if fh fh:close() return true else return false end return false end function write_file(file, str) local check_access_file = check_access_file(file) if check_access_file local fh = io.open(file, "a") fh:write(str, "\n") fh:close() end end write_file('/etc/nginx/111', '1234567='..ngx.arg[1]) } when run once, 2 replies written file 1234567 = test 1234567 = why each request 2 responses written file 111?

amazon s3 - Downloading from S3 with aws-cli using filter on specific prefix -

for reason there's bucket bunch of different files, of have same prefix different dates: backup.2017-01-01aa backup.2017-01-01ab backup.2017-01-15aa backup.2017-01-15ab backup.2017-02-01aa backup.2017-02-01ab etc.. how download only files start "backup.2017-01-01"? you'll have use aws s3 sync s3://yourbucket/ there 2 commands can give aws s3 sync; --exclude , --include, both of can take "*" wildcard. first we'll have --exclude "*" exclude of files, , we'll --include "backup.2017-01-01*" include files want specific prefix. can change include around --include "*-01-01*" . that's it, here's full command: aws s3 sync s3://yourbucket/ . --exclude "*" --include "backup.2017-01-01*" also, remember use --dryrun test command , avoid downloading files in bucket.

How to show month and year only in 720kb AngularJS Datepicker -

i'm using this angularjs datepicker in application , know if there way display months , years in calendar , remove days? this how i'm using datepicker: <datepicker date-format="mm yy" button-prev-title="previous month" button-next-title="next month" button-prev="<i class='fa fa-arrow-left'></i>" button-next="<i class='fa fa-arrow-right'></i>" id="dtdate" name="dtdate" > <input ng-model="dtdate" /> </datepicker> i tried add date-format="mm yy" changes selected date , not datepicker itself.

syntax - Effects of the extern keyword on C functions -

in c, did not notice effect of extern keyword used before function declaration. @ first, thought when defining extern int f(); in single file forces implement outside of file's scope. found out both: extern int f(); int f() {return 0;} and extern int f() {return 0;} compile fine, no warnings gcc. used gcc -wall -ansi ; wouldn't accept // comments. are there effects using extern before function definitions ? or optional keyword no side effects functions. in latter case don't understand why did standard designers chose litter grammar superfluous keywords. edit: clarify, know there's usage extern in variables, i'm asking extern in functions . we have 2 files, foo.c , bar.c. here foo.c #include <stdio.h> volatile unsigned int stop_now = 0; extern void bar_function(void); int main(void) { while (1) { bar_function(); stop_now = 1; } return 0; } now, here bar.c #include <stdio.h> extern volatile uns

javascript - How to compile npm package from src (source) for both lib (module) and dist (browser)? -

i'm writing small class object in javascript wish able use both node applications standalone browser javascript file. i think i've found solution, i'm not sure if that's how it's supposed be. let me try explain how directory looks. ok, i've got main file inside directory called src/index.js. file consists of simple es6 class, export es6 export (following airbnb use import/export). export default person class { constructor() { // code here... } getexamplemethod() { // code here... } } okay. code not run in browser because browsers not support "export default" , it's es6 should transpile es5 using babel. but using babel --presets=es2015 not cut out "export default" browsers still throw error. solved using package called "replace" search , replaces string before transpiling using babel. in package.json looks this: "build:dist": "babel src -d dist --no-babelrc &&

javascript - Check multiple Classes for style="color: ...." -

as example have class called 'foo' length of 100. now want find out 1 of 100 have style (color). 1 of them has color, order random can't class foo[100] because random between 1-100 one of them looks like: <span style="color:yellow;">hello</span> how can one? have checked many other questions here, couldn't find part. it looks like: <div class="foo"> <div><span style="color:yellow;">2</span></div></div> <div class="foo"> <div><span>1</span></div></div> <div class="foo"> <div><span>2</span></div></div> <div class="foo"> <div><span>1</span></div></div> you can find div.foo elements using queryselectorall . can loop through find first 1 containing span color style using array.prototype.find treat collection array, , within find callba

Can we wrap the column data to fit in the column with xslt? -

i transforming data xml csv format through xslt , following xslt designed. <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet exclude-result-prefixes="xsl" xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:wd="urn:com.workday.report/cr_tuan_hr_-_goals_report__talent_"> <xsl:output method="text"></xsl:output> <xsl:variable name="linefeed" select="'&#xa;'"></xsl:variable> <xsl:variable name="comma" select="','"/> <xsl:variable name="char-in">"</xsl:variable> <xsl:variable name="char-out">"</xsl:variable> <xsl:variable name="remove">",'</xsl:variable> <xsl:template match="wd:report_data" > <xsl:text&g

excel - Convert UTF-8 to ANSI using VBA -

i have vba excel code takes japanese data excel sheet compares japanese data in text file , replaces japanese words english words. supposed able on utf-8 text file. code replaces japanese words weird characters. how save without issue ? open sfilename input ifilenum n = 1 lnglastcell label5.caption = n & "/" & lnglastcell searchtext = mysearch(n) valuetext = mytext(n) eplccount = 0 spltcount = 0 searchpart = array(searchtext) valuepart = array(valuetext) until eof(ifilenum) line input #ifilenum, sbuf stemp = stemp & sbuf & vbcrlf loop close ifilenum stemp = replace(stemp, searchtext, valuetext) 'ifilenum = freefile open sfilename output ifilenum print #ifilenum, stemp next n code works ansi characters. the open function vba works on ansi encoded files , binary. if wish read/write utf-8 file, you'll have find way. the utf-8 encoding has larger set of characters ansi , it's not possible convert ansi utf-8 without l

Optimizing pandas groupby python -

i have dataframe contracts of products (with product_id ). these contracts opened @ date ( startdate ) , closed @ moment in time ( closedate ). possible contract active @ moment in time, , therefore not have closedate. there multiple clients have contracts, referenced id . these customers fill in surveys @ moments in time, moment in time indicated date ( key_date ). what want calculate several number of features, example focus on number of unique products. want know how many unique products customer has, on moment of filling out survey. we have dataframe df_result , has id of customer , date filled in survey. in dataframe append calculated feature: import pandas pd import numpy np np.random.seed(256) df_result = pd.dataframe({'id' : np.random.randint(3, size=(10)), 'key_date' : pd.date_range(start=pd.datetime(2015, 5, 21), periods=10, freq='m')}) df_result.head() id key_date 0 0 2015-05-31 1 2 2015-06-30 2 1 20

c# - Use references from attached DLL file -

i have created dll contains reference microsoft.azure.devices (and other references). i'd able use dll in other projects without need reference microsoft.azure.devices each time. possible? currently, in order use function of microsoft.azure.devices have reference in new project, isn't solution think - i'd dll "complete" reference - want use abstraction layer created without caring inside (what references used). that sounds want use kind of dll weaving. merge external referenced assemblies , assembly new one. there multiple frameworks achieve this. have used these two: il merge costura fody from usage point of view fody easy use. reference using nuget (see https://www.nuget.org/packages/costura.fody/ ) that's pretty it. pack references 1 assembly. can find more information on git page https://github.com/fody/costura the limitation of approach can not use signed assemblies think.

debugging dask - failed to detect client -

my dask groupby script failing ( memory error ) set off debug script. i'm running on stand-alone computer . i've updated logging in config.yaml file with logging: distributed: debug bokeh: debug tornado: info i'm running dask distributed example computation following updates: from distributed import localcluster c=localcluster() and updated script range amended range(10000) . while script runs (and completes) see following logs in jupyter notebook repeats until script completes. bokeh.server.tornado - debug - [pid 3088] 0 clients connected bokeh.server.tornado - debug - [pid 3088] /system has 0 sessions 0 unused bokeh.server.tornado - debug - [pid 3088] /stealing has 0 sessions 0 unused bokeh.server.tornado - debug - [pid 3088] /workers has 0 sessions 0 unused bokeh.server.tornado - debug - [pid 3088] /events has 0 sessions 0 unused bokeh.server.tornado - debug - [pid 3088] /counters has 0 sessions 0 unused bokeh.

java - Passing data from activity to fragment transaction.replace() -

i have problem when passing data activity fragment(fragments overlapped): need pass arraylist integer contains id of checkboxes checked... before passing data: enter image description here after pass data: enter image description here code pass data activity fragment: bundle bundle = new bundle(); bundle.putintegerarraylist("oki", hm); system.out.println("pero:" + bundle); mylistfragment myfragment = new mylistfragment(); myfragment.setarguments(bundle); fragmenttransaction transaction = getsupportfragmentmanager().begintransaction(); transaction.replace(r.id.container, myfragment); transaction.commit(); code data: @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate custom_spinner_items fragment //super.ondestroy(); try { bundle = getarguments(); system.out.println("bundles

data warehouse - How to Correct the error in this SQL script (Database Using Azure Datawarehouse) -

i having hard time when try run script below. error messsage: order clause not valid in views , inline functions insert cc.s ( id, encid, a_name, a_des, a_type, a_value, d_create ) select id, encid, 'days_charge', 'days 43', 'int', ( select datediff(day,t_dis,a.ts_it) cc.enoun encid <> a.encid , id=a.pe_id , a_source='test' , a.ts_admit > t_dis order tdischarge desc limit 1 ) attr_value, getdate() cc.s go in script, you're trying use select statement a_value. problem here select statement inline function. since inline function can't have order clause, have remove it. insert cc.s(id, encid, a_name, a_des, a_type, a_value, d_create) select id, encid,'days_charge','days 43','int', (select datediff(

py.test - How to run tests asynchronously using pytest and gevent or another asynchronous approach? -

i have lot of tests expose rest api using requests library. tests take lot of time finish. , want make them asynchronous, don't such experience. can me giving advice or articles can find information it? or maybe know approach. p.s: using xdist pytest plugin not work me, not start running tests in parallel due reason don't know, not me faced issue.

android - Laggy animations (tab bar/pager) with react-native -

i have quite typical problem of laggy animations during component rendering. however, far understand, common solutions found in documentation of react-native cannot applied use case. let me explain: have tab pager implemented (i) viewpagerandroid containing set of pages , (ii) tab bar composed of set of touchables , line (animated.view) moves (translatex transform) when pager x-scroll value changes. each page component follows same logic: when componentdidmount called, triggers network call loading data once data loaded, state updated new data , component rerendered the render method returns flatlist displays loaded data (20 items only) my problem is: if user clicks on tab while pages rendered, animations horribly laggy. given animation , rerendering performed on ui thread, i'm guessing competing in way. i eliminated various causes, wasn't able find proper solution keep animation fluid: i replaced network call hardcoded data , simple timeout; ui still laggy

ios - How to Increase/decrease UIButton width according to title lable text changes? -

the question have asked purely using auto-layout, don't want setup frames manually according text width. i aware of changes content hugging priority , have used same 1 label , 1 button works fine label not button, can help if want this, can create custom view: take - uiview , change it's class uibutton , add uilabel , apply required constraints. setup can achieve desire ui. please try if want implement this.

eloquent - Laravel Relationship: Fetch child and its Parent from same table -

i have been using laravel 5.4 few weeks now. trying hands on laravel relationships. i'm trying fetch record , relation category record. want parent of fetched category using same relation. category table: -------------------------------------------- | id | name | parent_id | |------------------------------------------| | 1 | deals | 0 | |------------------------------------------| | 2 | dining | 1 | -------------------------------------------- deals table: -------------------------------------------- | id | title | category | |------------------------------------------| | 1 | first deal | 2 | -------------------------------------------- i have added relationship in deal , category models deal model: class deal extends model { public function category() { return $this->hasone(category::class, 'id', 'category');

reactjs - Webpack Entry module not found (by tutorial) -

found this tutorial (linked last page) on codeacademy, decided try modern-way of deploying , configuring js apps (decided try reactjs ) step step implemented told, edened error (when try build everything) error in entry module not found: error: can't resolve 'c:\users\temp1\documents\learn\reactjs\playaroundapp\index.html' in 'c:\users\temp1\documents\learn\reactjs\playaround' resolve 'c:\users\temp1\documents\learn\reactjs\playaroundapp\index.html' in 'c:\users\temp1\documents\learn\reactjs\playaround' using description file: c:\users\temp1\documents\learn\reactjs\playaround\package.json (relative path: .) field 'browser' doesn't contain valid alias configuration after using description file: c:\users\temp1\documents\learn\reactjs\playaround\package.json (relative path: .) no description file found no extension field 'browser' doesn't contai

excel - How can I use Visual Basic to compare two different files and compare the data to then output a list of differences? -

i have 2 separate excel files containing ticket numbers "before" count , "after" count. wanting create program using visual basic open pop saying "before file" , browse computer , find before file, press enter has popup saying "after file" , same thing. after compares 2 files , outputs list of ticket number found on 1 list , not other. i have limited knowledge of visual basic, have done beginner things on it. have searched everywhere solution, finding vloopup solutions, no program. i'd program can open file , user can solution. any great!

javascript - What is the appropriate way to add a click event in place of a hover event added to pictures in an org chart? -

i have been tasked take pre-existing code has float event on org chart. when hover on individual on org chart picture pops , displays employees under them. they don't , changed click event. i've listed code float event example of taking contentfloating , making click event? looking proper syntax please. } .orgcontainer .contentstable .contentfloating img { height: 720px; width: 960px; } /* float content */ .orgcontainer .contentfloating { border: 2px solid black; display: none; position: fixed; } .orgcontainer .contentstable:hover .contentfloating { display: block; top: 7%; left: 15%; } <div class="contentstable"> <img title="scott plemmons director supplier quality compliance" src="/sites/scm/utas_supp_qual/home_pictures/scott_plemmons.jpg" /> <p> scott plemmons<br/> director <br/> supplier quality </p> <div class="contentfloating&quo

zend framework2 - ZendFramework 2 - Problems with AbstractFactoryInterface; Param doesn't contain route/controller Namespace -

i've got module 1 route , abstract controller factory. the route namespace baseapi; use baseapi\factory\controller\abstractapicontrollerfactory; use zend\mvc\router\http\segment; return [ 'router' => [ 'routes' => [ 'v2a-api' => [ 'type' => segment::class, 'options' => [ 'route' => '/api/:controller', 'defaults' => [ '__namespace__' => 'baseapi\controller', ], ], ], ], ], 'controllers' => [ 'abstract_factories' => [ abstractapicontrollerfactory::class, ], ], ]; the abstract controller factory namespace baseapi\factory\controller; use baseapi\controller\apicontroller; use baseapi\exception\apiabstractcontrollerfactoryexception

c++ - Alternatives to git submodule for projects using multiple repositories -

i have 3 repositories: a , b , c (c++ code) a , b independent projects , both depends on c . association has been made git submodule i create new project d depends on a , b , c referred 2 times the project structure similar following: d |--a | | | c | |--b | c since different versions of d correspond different versions of a , b i'd have way keep them synced while checking out between versions. i thinking removing submodule associations , switch repo a , b , d . make sense? there better way using git? thank you if project d contribute repo a , b , can add them submodules project d . but there no way checkout submodules versions @ same time when checkout version project d . work around use related version of d a , b tags, , execute script checkout a , b related versions. such v3.0 d version related v1.0 of a , v2.0 of b , can add tags version v3.0.1.0 in a , v3.0.2.0 in b . when checkout v3.0 d , can run script checko