Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
robostac
Sep 23, 2009
It looks very much like you have a .git in your home folder. Git will check parent folders recursively until it finds one with a .git folder inside it.

Adbot
ADBOT LOVES YOU

ToxicFrog
Apr 26, 2008


Boris Galerkin posted:

I have a question about logging practices. Basically what's the "best practice" placement of logging outputs? Here's a silly example

code:
# main is the executable called from the script
def main():
    logger.debug('calling do_something')
    do_something()
    logger.debug('do_something successful')

# random library function
def do_something():
    logger.debug('doing something')
    print('Hello world')
    logger.debug('something has been done')
Silly example aside is it considered better practice to write to a log outside of the function call but inside the main executable, inside the library function, or in both?

In that example I'd probably put it in do_something, so that the log messages continue to appear when it's called even as the rest of the program is restructured so that where it's called from changes. Although for that sort of "logged every time a function is called" message I prefer to use TRACE over DEBUG if the logging library supports it.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Boris Galerkin posted:

I have a question about logging practices. Basically what's the "best practice" placement of logging outputs? Here's a silly example

code:
# main is the executable called from the script
def main():
    logger.debug('calling do_something')
    do_something()
    logger.debug('do_something successful')

# random library function
def do_something():
    logger.debug('doing something')
    print('Hello world')
    logger.debug('something has been done')
Silly example aside is it considered better practice to write to a log outside of the function call but inside the main executable, inside the library function, or in both?

If you’re going to rip it out before shipping, why care? If you’re not, be mindful of how chatty libs you maintain are, how often the function is going to be called, and what the logging function does. You don’t want your logs to cause perf or resource issues.

If you’re using python, and your logs look like that, look into decorators.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Sad Panda posted:

Honestly, no idea how to do that either. Is there no way of telling it, the cwd is where you are? When I was running things through Sublime Text it'd work perfectly like that and if I say logging = /logs/audit.log, it'll put it in the logs subdirectory relative to that file.

That's weird because /logs/audit.log is not a relative path! That's an absolute path because it beings in a /

All I'm suggesting is that you maintain a file - call it settings.py if you want - that's just something like
Python code:
logging_direcotry = "/logs/audit.log"
output_files_to = "/Users/sadpanda/Desktop/buttes"
And then, when you want to reference them, you just import them from the file like anything else you would in Python. This way, you can run the program from anywhere and get consistent results. If you want paths relative to the script you're running, it would look more like
Python code:
import os

_script_root = os.path.realpath(__file__)

logging_direcotry = "/logs/audit.log"
output_files_to = os.path.join(_script_root, "/buttes")
So your logging will always go to the absolute path and output would always go to the directory buttes that's a sibling of the settings file (which I'm assuming is in your project root, here).

Note that the __file__ magic doesn't work in the REPL. Or at least didn't used to.

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Boris Galerkin posted:

I have a question about logging practices. Basically what's the "best practice" placement of logging outputs? Here's a silly example

Silly example aside is it considered better practice to write to a log outside of the function call but inside the main executable, inside the library function, or in both?

I'll do either depending on what I'm trying to accomplish. Putting logging inside the function works well unless the function has multiple exit points and you want to log the same thing regardless of which is taken.

Sad Panda
Sep 22, 2004

I'm a Sad Panda.

robostac posted:

It looks very much like you have a .git in your home folder. Git will check parent folders recursively until it finds one with a .git folder inside it.

I ended up finding one. No idea how it got there but hopefully that's the problem resolved.

Hunt11
Jul 24, 2013

Grimey Drawer
This is a VBA question which I am not sure where to ask so I am going to drop it here.

I have a code for a stock homework assignment where I need to compare what the market opened up at the start of the year for a certain stock and where it closes. If it was just one stock then that would be simple enough but I need to do this for hundreds of stocks.
code:
For i = 2 To Range(Range("A2"), Range("A2").End(xlDown)).Count    
        If Cells(i + 1, 1).Value <> Cells(i, 1).Value Then
          Ticker = Cells(i, 1).Value
          Ticker_Total = Ticker_Total + Cells(i, 7).Value
          Total_Change = Cells(Right(i, 6)) - Cells(Left(i, 3)).Value
          Range("I" & Summary_Table_Row).Value = Ticker
          Range("J" & Summary_Table_Row).Value = Total_Change
          Range("K" & Summary_Table_Row).Value = Total_Change / 100
          Range("L" & Summary_Table_Row).Value = Ticker_Total
          Summary_Table_Row = Summary_Table_Row + 1
        Ticker = 0
        Ticker_Total = 0      
        Else
          Ticker_Total = Ticker_Total + Cells(i, 7).Value
        End If
      Next i
This is the code I have so far and while it works for finding the volume of the stock that has been traded, I have not been able to get any workable results for the total change. My original attempt had this
code:
If
    Total_Change = Cells((i, 6)) - Cells((i, 3)).Value
    Total_Change=0
Else
    Total_Change = Cells(Right(i, 6)) - Cells(Left(i, 3)).Value
and while it generated a result it was the wrong one when I compared the two values by hand.

Hunt11 fucked around with this message at 17:09 on Jun 6, 2018

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Hunt11 posted:

This is a VBA question which I am not sure where to ask so I am going to drop it here.

I have a code for a stock homework assignment where I need to compare what the market opened up at the start of the year for a certain stock and where it closes. If it was just one stock then that would be simple enough but I need to do this for hundreds of stocks.

For i = 2 To Range(Range("A2"), Range("A2").End(xlDown)).Count
If Cells(i + 1, 1).Value <> Cells(i, 1).Value Then
Ticker = Cells(i, 1).Value
Ticker_Total = Ticker_Total + Cells(i, 7).Value
Total_Change = Cells(Right(i, 6)) - Cells(Left(i, 3)).Value
Range("I" & Summary_Table_Row).Value = Ticker
Range("J" & Summary_Table_Row).Value = Total_Change
Range("K" & Summary_Table_Row).Value = Total_Change / 100
Range("L" & Summary_Table_Row).Value = Ticker_Total
Summary_Table_Row = Summary_Table_Row + 1
Ticker = 0
Ticker_Total = 0
Else
Ticker_Total = Ticker_Total + Cells(i, 7).Value
End If
Next i

This is the code I have so far and while it works for finding the volume of the stock that has been traded, I have not been able to get any workable results for the total change. My original attempt had this
If
Total_Change = Cells((i, 6)) - Cells((i, 3)).Value
Total_Change=0
Else
Total_Change = Cells(Right(i, 6)) - Cells(Left(i, 3)).Value
and while it generated a result it was the wrong one when I compared the two values by hand.

I don't know the answer, but you're more likely to get help if use code tags to format your code. Click the button labeled "bbcode" when you post or edit your post to see instructions on how to do that.

Hunt11
Jul 24, 2013

Grimey Drawer

Thermopyle posted:

I don't know the answer, but you're more likely to get help if use code tags to format your code. Click the button labeled "bbcode" when you post or edit your post to see instructions on how to do that.

Just did that and thanks for the advice.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

It's honestly really hard to parse that without being able to see the spreadsheet it's pulling data from (not that I know VBA anyway, but yknow). A pic of a few rows and the bad results would help! Also what does "not getting any workable results" mean - is the calculation wrong, or is there some kind of error or something?

It might help to create some dummy data with only a few entries for a stock, that way you can get a better idea of where it's going wrong. Or if you have a debugger, definitely use that to step through the program and watch what it's doing, and work out if those are the steps you meant

Hunt11
Jul 24, 2013

Grimey Drawer


Here is a picture with the issue. So the number in the top box is where the market closes at the end of the year so the result for the B ticker should be 12.03. In terms of what is going wrong with my calculation the formula is adding up every number in the F and C column and then subtracting the result.

huhu
Feb 24, 2006
I've got a bunch of boilerplate code I need to generate for a project. If I want to create a new Foo component I've got

code:
Foo/
  Foo.js
  Foo.styles.js
  package.json
And an example of Foo.js
code:
import React, { Component } from 'react';

import {
} from './Foo.styles';

export default class Foo extends Component {
  render() {
    return (
	<p>some foo text</p>
    );
  }
}
Is there an easy tool out there for generating this kind of stuff? I've never looked into automating boilerplate generation before.

tracecomplete
Feb 26, 2017

Sounds like a Yeoman problem.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Hunt11 posted:



Here is a picture with the issue. So the number in the top box is where the market closes at the end of the year so the result for the B ticker should be 12.03. In terms of what is going wrong with my calculation the formula is adding up every number in the F and C column and then subtracting the result.

I assume it's a string of B ticker results followed by BA tickers, right?

Look at where you're putting your results in the summary bit. Where are you getting your data for Total_Change? You said it calculates the year's volume correctly - how are you handling that differently?

Spoilered for homework (try and work it out first because coding is 90% staring at a thing that doesn't work going ???)
Your volume works because you're keeping a running total for every row in the year. Total_Change needs to do that too, or at least keep track of the year's opening value, or a reference to the cell where it is. Right now you're comparing the opening and close on the last day

At least I think that's what you're doing - I don't know the syntax, but from looking it up, the Right(i, 6) stuff takes 6 characters from the right side of i? I don't know what Cells(Right(i, 6)) - Cells(Left(i, 3)).Value is doing. It would usually be Cells(i, 6).Value - Cells(i, 3).Value right to compare on the same row, right? Also you're missing a .Value off the first Cells call if that matters

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

huhu posted:

I've got a bunch of boilerplate code I need to generate for a project. If I want to create a new Foo component I've got

code:
Foo/
  Foo.js
  Foo.styles.js
  package.json
And an example of Foo.js
code:
import React, { Component } from 'react';

import {
} from './Foo.styles';

export default class Foo extends Component {
  render() {
    return (
	<p>some foo text</p>
    );
  }
}
Is there an easy tool out there for generating this kind of stuff? I've never looked into automating boilerplate generation before.

I wonder if there's a sort of "React CLI"... That's exactly the sort of thing that Angular CLI does.

Hunt11
Jul 24, 2013

Grimey Drawer
[code]
If Cells(i + 1, 1).Value <> Cells(i, 1).Value Then
Total_Change = Cells((i, 6)) - Cells((i, 3)).Value
Total_Change=0
Range("J" & Summary_Table_Row).Value =Total_Value
Total_Change =0
Else
Total_Change = Cells(i, 6)) - Cells(i, 3)).Value
[code]

I realized what I posted was wrong, and this is what I originally used. The issue is that I need to compare the first i,3 in the sequence with the last i,6.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Remember that i is the number of the current row youre looking at. When you start a new sequence, you need to store the value of i for that row, so when you get to the end you can compare (i, 6) with (first, 3). Or you can just store the value, so instead of looking up the first cell you can do (i, 6) - openingValue

Your code basically runs like this, right
code:
loop over all the row numbers using i as the index:
	if the next row's ticker is different from this one:
		get all the final data for this sequence
		stick it all in the current summary row
		move to the next summary row and reset data for the next sequence
	otherwise:
		add this row's data to running totals for the current sequence
it's a little awkward, but you could set the reference/value for the start of the new sequence when you're doing the reset stuff. It's probably cleanest to store the row number (Sequence_Start = i + 1), that way when you're on the last row of your data you're not trying to read data from a cell that might not exist, you're just storing the number of that hypothetical next row. Then your loop ends and it doesn't matter, if you get me!

TheReverend
Jun 21, 2005

Is Xamarin still a pile of poo poo?

(I asked this question about 5 years ago and the answer was "you bet")


I'm mainly interested in Xamarin.Forms

Looking for the feasibility to build:

App A:
- SQLite
- Barcode scanning via camera
- Rest Calls
- Map with light customized markers
- Location Services
- Everything else just Forms.

App B:
- Same as above but with
- Bluetooth LE connections

roadhead
Dec 25, 2001

Anyone got a handy link for working with an external .EXE from within a WPF UI? I had a conversion process for our old files that are MS Access DBs, so the converter must be built as a 32-bit EXE/DLL because of the garbage that is the OLEDB.

So i've got to call out to that external EXE and then wait on its completion, right now the solution I have fails sometimes because I try and create the IO tab before the conversion s finished...

mystes
May 31, 2006

roadhead posted:

Anyone got a handy link for working with an external .EXE from within a WPF UI? I had a conversion process for our old files that are MS Access DBs, so the converter must be built as a 32-bit EXE/DLL because of the garbage that is the OLEDB.

So i've got to call out to that external EXE and then wait on its completion, right now the solution I have fails sometimes because I try and create the IO tab before the conversion s finished...
How are you currently launching the exe that doesn't allow you to deal with this?

If its System.Diagnostics.Process can't you just use an event or something?

roadhead
Dec 25, 2001

mystes posted:

How are you currently launching the exe that doesn't allow you to deal with this?

If its System.Diagnostics.Process can't you just use an event or something?

As in move the part that responds to the finish into an event handler? That sounds interesting I'll try that.

mystes
May 31, 2006

roadhead posted:

As in move the part that responds to the finish into an event handler? That sounds interesting I'll try that.
Yeah. Just be aware that you may have to set EnableRaisingEvents to true first for it to work, but then I think you should just be able to add an event handler for the Exited event.

mystes fucked around with this message at 19:53 on Jun 9, 2018

Chunjee
Oct 27, 2004

I need to add logging to my little app, I've read over and over that all logging should be sent to stdout; I agree, our now ex-developers would log directly to disk and this predominantly Windows environment would crash when the C:/ drives filled up. lol ok


But how do I capture and save that stdout to disk on a remote logging machine? Closest answer I could find:

quote:

Standard out is an output stream that can be captured and redirected to a variety of sources. It's generally a best practice, but it is also a more advanced option as it requires server level configuration to capture the stream and redirect it to the desired destination.

Is standard out logging primarily for container level deployments? I'm just working with a bunch of Windows VMs here in legacy.


Sumologic asks me this:

MrMoo
Sep 14, 2000

A lot of the logging-as-a-service things like reading from log files as they can do it asynchronously on their own time. Syslog is more for the system and HTTP for web clients.

I've actually done one project for Sumologic and they explicitly said to dump to a local file.

Boost.Log has some nice examples. For the one time I BYOL I used ZeroMQ which I think Loggly uses too.

MrMoo fucked around with this message at 19:24 on Jun 18, 2018

JawnV6
Jul 4, 2004

So hot ...
I need some historical weather data for rainfall. Nothing older than 6 months, hourly would be fantastic, I have the exact GPS coordinates I'm interested in but something county-level/ZIP code would be fine as well.

OpenWeatherMap has what I'd need... for $950/month. This is a goof-off thing, I don't really want to pay for it and certainly not that much. Weather Underground is free, but rainfall data is daily. That'll work in a pinch, but I'm curious if someone knows a good source for this kind of data.

The Fool
Oct 16, 2003


The national weather service has an api, maybe that will help?

https://www.weather.gov/documentation/services-web-api

JawnV6
Jul 4, 2004

So hot ...
Gosh that's... complete. I can pick a particular station and go digging through the history it seems? But I think I can get what I need with a few queries, start with the GPS coordinate, figure out the grid, go back as far as I need.

Thanks!

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



There's also https://darksky.net/dev/docs#time-machine-request which might be simpler and you can do 1000 calls/day for free

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

My General Programming Question is: Is this not the coolest paper?

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Thermopyle posted:

My General Programming Question is: Is this not the coolest paper?

It is with high probability the coolest paper.

TheresaJayne
Jul 1, 2011

leper khan posted:

It is with high probability the coolest paper.

made no sense to me, what i want to see is Robert Morris' Spell checker code, It was small, compact and had no dictionary yet it got a 99% hit rate.

unfortunately his son became more famous than he did.

Edit: found a reference to it
The second does not use a dictionary at all (Morris and Cherry 1975). Like the previous method, it divides the text into trigrams, but it creates a table of these, noting how often each one occurs in this particular piece of text. It then goes through the text again calculating an index of peculiarity for each word on the basis of the trigrams it contains. Given pkxie, for instance, it would probably find that this was the only word in the text containing pkx and kxi (and possibly xie too), so it would rate it highly peculiar. The word fairy, by contrast, would get a low rating since fai, air and iry probably all occur elsewhere, perhaps quite often, in the passage being analysed. Having completed its analysis, it draws the user's attention to any words with a high peculiarity index. Like the previous method, it would fail to spot a high proportion of ordinary spelling errors, but it is quite good at spotting typing errors, which is what it was designed for. An advantage that it has over all dictionary-based methods is that it is not tied to English; it will work on passages of, say, French, German or Greek.

His Son: https://en.wikipedia.org/wiki/Robert_Tappan_Morris

TheresaJayne fucked around with this message at 07:26 on Jun 20, 2018

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

TheresaJayne posted:

made no sense to me, what i want to see is Robert Morris' Spell checker code, It was small, compact and had no dictionary yet it got a 99% hit rate.

Might be in this paper if you have IEEE access.
https://ieeexplore.ieee.org/document/6593963/

Dominoes
Sep 20, 2007

ulmont posted:

Might be in this paper if you have IEEE access.
https://ieeexplore.ieee.org/document/6593963/
http://sci-hub.tw/https://ieeexplore.ieee.org/document/6593963/

CzarChasm
Mar 14, 2009

I don't like it when you're watching me eat.
Cross Posting from Stupid Questions thread
I'm trying to build a form that will import data in several variables and give them proper case. So for example JANE SMITH run through this code will change to Jane Smith. Likewise, jane smith becomes properly capitalized.

print @str.substring($customer.firstname,0,1);
print @str.substring(@str.tolower($customer.firstname),1) & " ";
print @str.substring($customer.lastname,0,1);
print @str.substring(@str.tolower($customer.lastname),1);

This works fine. I'm trying to do the same thing for addresses, and those are stored as 123 fake st and I want them to be 123 Fake St
The problem is I don't know how long the numerical part of the address is, so I can't just say skip the first three characters, plus a space, and then capitalize like above.

So, what I was thinking was to make a loop that would stop at each space and effectively break the line into however many parts the street address is, and then capitalize the first character in each part. But again, I don't recognize this language and I did not find any examples of doing what I want.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

CzarChasm posted:

Cross Posting from Stupid Questions thread
I'm trying to build a form that will import data in several variables and give them proper case. So for example JANE SMITH run through this code will change to Jane Smith. Likewise, jane smith becomes properly capitalized.

print @str.substring($customer.firstname,0,1);
print @str.substring(@str.tolower($customer.firstname),1) & " ";
print @str.substring($customer.lastname,0,1);
print @str.substring(@str.tolower($customer.lastname),1);

This works fine. I'm trying to do the same thing for addresses, and those are stored as 123 fake st and I want them to be 123 Fake St
The problem is I don't know how long the numerical part of the address is, so I can't just say skip the first three characters, plus a space, and then capitalize like above.

So, what I was thinking was to make a loop that would stop at each space and effectively break the line into however many parts the street address is, and then capitalize the first character in each part. But again, I don't recognize this language and I did not find any examples of doing what I want.

What you're looking for in general called a regular expression (regex). In javascript, doing something like:

code:
function camelize(str) {
  return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
    if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces
    return index == 0 ? match.toLowerCase() : match.toUpperCase();
  });
}
Would go through the string and make the first letter uppercase.

Unfortunately, I don't recognize the language in the file, either. The string concatenation operator is &, which is strange. Do you have more context clues about the language (like, a filename extension)? Also, is the text of the script exactly as in the original file?

My best guess from looking at http://rigaux.org/language-study/syntax-across-languages.html#StrngStrnCnct is that it might be awk, based on the names of the methods and sigils present in the variable names. In that case, this might work: https://www.gnu.org/software/gawk/manual/html_node/String-Functions.html

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
Also, most languages (but possibly not the weird one you’re using) will have some sort of capitalize function and that’s what you should be using unless the goal is simply to learn.

reversefungi
Nov 27, 2003

Master of the high hat!
Usually they have a name like "title casing", or at least that's what C# calls it.

CzarChasm
Mar 14, 2009

I don't like it when you're watching me eat.
I apologize, in my other post I mentioned that I thought it looked like AWK or bash, but it appears to be something proprietary. Thank you all for your help. I'm going to try their support and see what they say.

tricksnake
Nov 16, 2012
Best/popular coding practice websites/games/apps? OK I have learned C++. Next I get bombarded with "just go code stuff" from every person I ask.

Adbot
ADBOT LOVES YOU

Dominoes
Sep 20, 2007

tricksnake posted:

Best/popular coding practice websites/games/apps? OK I have learned C++. Next I get bombarded with "just go code stuff" from every person I ask.
Need to be more specific.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply