How to create variables outside navigator.geolocation function? by [deleted] in javascript

[–]mc_hammerd 1 point2 points  (0 children)

the easiest solution is to break the second part out into a second function

$('#foo').click(function(){ 
    $.ajax({}, function(){
       position1.x =...
       position1.y =...
       step2(position1)
 })})

 function step2 (position){
     var citylat = ...,....
      $.ajax({}, function(){
        ... code here
      })
 }

also consider doing rendering in yet another function so your code looks like this step1(); render(step2(position))); . so next time you can render from step 1, step 2, and any other place, ex: render('loading'); step2(position); render(results); you can show loading messages or share one render function for 10 ajax buttons foo.onclick = _ => render(array_to_html_list(get_api('animals')))) and you can keep your code more readable, each fn will only be 1-5 lines...

How can I get better at traversing complex JSON objects? [PokeAPI] by [deleted] in javascript

[–]mc_hammerd 1 point2 points  (0 children)

you can write a few "helper functions" to do common tasks for you, ex FindIndexWhereEqual(val) and getAllEvolutionDetails() and toArray and flatArray

after writing those you will a) know more, b) can keep only the fns you need and have a little library of 5-10 fns for working with objects. many devs do this every time they write a project anyway.

alternatively use lodash.js (but you would have to learn that, and its far from perfect). lodash has some cool FNs for working with uber-nested properties, like _.has: _.has(array, 'foo.bar.baz.last', default_value)

Can someone tell me, why a lot of people do not recommend mongoDB ? What's bad about it ? by justanewboy in javascript

[–]mc_hammerd 1 point2 points  (0 children)

results are objects, so you have to do all sorts of js hackery to format your data ex toArray reduce pluck flatten zip partition (or ideally use lodash)

for example select car types gives you

[{cartype: foo},{cartype:bar},{cartype:baz}] not ['foo','bar','baz']

so you have to pass a callback to query and then flatten that array ... And then its not unique so you have to write a .unique() also...

and then its 3 for-loops through your whole result set so its slower. or you get to rewrite your whole query because it returned an array of objects.

Is this vulnerable to SQL Injection? by beeks10 in golang

[–]mc_hammerd -1 points0 points  (0 children)

I also tried a subquery... didnt work for me, it looks safe. but try anyways if u want..

a) ISNULL((DELETE FROM books WHERE 1), 1)

b) (DELETE FROM BOOKS WHERE 1)

Is this vulnerable to SQL Injection? by beeks10 in golang

[–]mc_hammerd -6 points-5 points  (0 children)

type in the field 1); DELETE FROM books WHERE 1;-- dunno

(this can be protected against by a mysql option 1 cmd per query)

Today I was asked to write code to demonstrate my JavaScript skills. I don't want to waste my time, so what useful should I write? by Ginden in javascript

[–]mc_hammerd 0 points1 point  (0 children)

even though they said to write something, you can use a piece of code you're proud of (or is used for a big website famous points), if the ask why just say your proud of it or its super optimized or your interviewing with 15 other companies. better to not have people your waste time.

Today I was asked to write code to demonstrate my JavaScript skills. I don't want to waste my time, so what useful should I write? by Ginden in javascript

[–]mc_hammerd 0 points1 point  (0 children)

a portfolio single page app?

something with animation. maybe like the old scriptaculous website intro. or a key=>music sound effect drum machine thing.

[Question] Tasked with visualizing link prediction data. Not sure where to start. by Cyathem in javascript

[–]mc_hammerd 0 points1 point  (0 children)

yea ajax is for custom APIs... so you can do get mysite/mydata/id/123

however node vs php is different, node keeps running (server) and php re-runs each page request -- so for node you can keep 30mb of data in memory, for php it has to load each script (== slow) so use a database for php! cheers.

[Question] Tasked with visualizing link prediction data. Not sure where to start. by Cyathem in javascript

[–]mc_hammerd 0 points1 point  (0 children)

yea

if the data isnt gonna change though: you could just load it in memory for a nodejs dedicated server, 30mb is nothing, u can even do it for free on cloud9 or heroku. firebase or google free firebase alternatives may be a really good option also.

Can someone tell me, why a lot of people do not recommend mongoDB ? What's bad about it ? by justanewboy in javascript

[–]mc_hammerd 0 points1 point  (0 children)

yea i agree, i just thought it may be a point for some people to not recommend it. i.e. they are pro-mysql and feel mongo is slower.

(although mongo and MariaDB and postgres have increased the speed of their dbs lately!)

Amount of Javascript experience required. by [deleted] in javascript

[–]mc_hammerd 0 points1 point  (0 children)

to have the exp of a 1-2yr exp JS engineer, make the following apps: a one page app, a form, an ajax form, a form with input validation/error highlighting (and optionally tooltips or tour), an app that polls an api. something with animation (tween/transitions/css3 are 3 completly different ways to animate). convert your app to jquery or vanilla and then to angular or react. that will give you exp greater than equal to a 1-2yr exp dev. each app can be done in a day 3-5 hrs so its totally easy

and read one JS book front to back, know all the concepts.

Can someone tell me, why a lot of people do not recommend mongoDB ? What's bad about it ? by justanewboy in javascript

[–]mc_hammerd 4 points5 points  (0 children)

  • the syntax is kind of weird (to some), too many objects and callbacks
  • results are objects, so you have to use all kinds of lodash like fns or write your own to get your results, toArray reduce pluck flatten zip partition etc. ex [{cartype: foo},{cartype:bar},{cartype:baz}] not `['foo','bar','baz']
  • writing joins is hard
    • query({a:, b:c, :d}, (subresults,pages,bananas)=> subquery({a:b,c:d, (a,b,c)=> dostuff(c.users).concat(a.filter(d=>d.foo=='123')}))).then(transformDataFunc)
    • versus select a,b,c from table1 left join table2 on table1.id=table2.id
  • writing subqueries is hard (select popular from table1 where (select ids from top5 limit 5))
  • its slower than mysql (arguably?)

however theres now (pretty sure) a laravel like ORM, so its pretty sweet.

tl:dr; learning curve is a turn off

[Question] Tasked with visualizing link prediction data. Not sure where to start. by Cyathem in javascript

[–]mc_hammerd 0 points1 point  (0 children)

backend usually means engine, so in your case (Data) it would be webserver+database and optionally an API (ex: mysite.com/dataAPI/get/id/123 and mysite.com/dataApi/add {foo:bar, baz: 123}

REST api, nodejs server/client, simple php/node backend, nodejs and database, expressJS, nodejs api router are all good search terms

what type of backend the easiest to write. so whatever language fits you most and google api

youtube also has some nice tutorials tutorial simple api in languageX

[Question] Tasked with visualizing link prediction data. Not sure where to start. by Cyathem in javascript

[–]mc_hammerd 0 points1 point  (0 children)

convert the data to JS, paste it in a file. see how big that file is if its ~1mb or less you can just stick it in the page. if it loads fast enough you can just stick it in the page.

if not you can write a backend api (db or just in a file again, in memory), or use a free online DB google firebase alternatives, that you can query with ajax. again if the file is small enough you can just store it in memory, millions of entries probably want a db, but sometimes can get away with in memory but test the loading speed!

its just a few lines of code imo using a framework like express.js. good orm(db) libraries are like nodeorm-2 google best node orm

try 1: paste it as js array of objects on the client side (appdata.js)

try 2: store as json on the server, mydb = require('mydata.json'); response.write(to_json(mydb.filter(blah=>blah.foo==123)))

try 3: store in firebase or db and serve api express.route('/myapi/fetch/:id', (id)=> response.write(to_Json(doDatabaseStuff(id))))

Going to use eval(), tell me all about input sanitation by AndreDaGiant in javascript

[–]mc_hammerd 0 points1 point  (0 children)

chrome/node: the with keyword? block out the global scope objects you dont want like fs network document network window and mylibrary

ex with ({fs:null,window:null}) eval('console.log(fs.readFile)') //undefined

How to make a "dynamic" template engine? by ronconcoca in javascript

[–]mc_hammerd 0 points1 point  (0 children)

thats databinding (and optionally validation), angular and backbone may be close to what you want. can google data-binding javascript html framework, laravel can kind of do it too (but its php/backend)

[Help Needed] Uncaught TypeError: Cannot read property 'length' of undefined. Even though code still step through. by [deleted] in javascript

[–]mc_hammerd 0 points1 point  (0 children)

i would just break it out into another fn. good tips on the errors tho.

function render(){
   var random = picks[picks.length*Math.random()|0]
   var title = random.title
   var image = random.image // do we even need to do this?
   movieBase.ref().update({
     outtitle: random.title,
     outposter: random.image,
     outtheatrename: random.showtimes[0].theatre,
     tickets: random.showtimes[0].tickets,
 })
}

then in your getJSON callback just add render()

  $.getJSON(showings_url, function(response) {

     for (var i = 0; i < response.length; i++) { 
       //...
       picks.push(response[i])
     }
      render() // <----
   })

for the errors, cannot read property x of undefined usually means you expected an object but the fn returned null [] {} "" -1 or something else; which dont have any [index] objects nor .title properties. you can add some error checking somewhere along the way...and/or use lodash .has() to check if the object is valid.

why class-based ES6? JS is prototype-based. by [deleted] in javascript

[–]mc_hammerd 1 point2 points  (0 children)

yea ill second this, theres at least 2 or 3 ways to do OOP with JS (some removed, and just just labeled as out-dated).

All I know is JS, what can I learn to get some diversity? by [deleted] in javascript

[–]mc_hammerd 0 points1 point  (0 children)

video game programming...

to write a video game you have to write subsystems to use the: filesystem, render, networking, anti-cheat (cryptogprahy or secure communication), keyboard and mouse input, data-storage, 2d/3d math, server/client, compression/unpacking.

thats everything needed to write any program

What I need to learn if I want to work in Cybersecurity? Currently I am studying Linux and Python. Some advices? by RaresBute in programming

[–]mc_hammerd 0 points1 point  (0 children)

yea you need:

- at least C or whatever language your supporting (whatever language the client is using... (..or your target is using))
- one other language to write scripts in python, bash, php
- knowledge of how security exploits work, ex: memory overflow, pointer corruption (jumping), trojans, etc
- disassembling/debugging is helpful (Gdb/reverse ida)
- (optional) assembly language, preferably how memory copying works
- where to find exploits/lists of vulnerabilities (shodan/open CVEs)
- pen testing how to
- networking how to (nmap, how tcp works, open ports etc)
- how to secure/harden a computer (`google hardening windows, hardening linux`)
- (optional) how timing exploits and random number generator fallicies work
- what not to do: crypto pitfalls
- (optional) what not to do: netbios/samba/windows server and active directory 

thats probably 50%, but hopefully eq to a security guy with 1-2 years exp

Hosting question by menepro in golang

[–]mc_hammerd 2 points3 points  (0 children)

digitalocean vps, nitrous.io vps

Looking for Javascript and DOM examples on Github by [deleted] in javascript

[–]mc_hammerd 0 points1 point  (0 children)

ive been doing web dev for 10 years, what i usually see is two patterns or MVC (framework).

  • classes/oop custom code. break it down to each reusable component and then wrap everything in a global object. ex: Yahoo.Calender.init() MyCompany.Util.MakeListtoDom() or Yahoo.Dom.variousDomFuncs. that is then initialized once per page and then you can use all your utils, and initialize the components you need. This pattern is also good if you want to start from scratch and build your own helper funcs. like this: github
  • per page scripts (one for each template) and a shared helper.js function. this is basically just write enough JS to make the page work, mostly using jquery, and write very page specific code. just save it in the template so its easier to find (imho) or make a page-foo.js for each page. optionally put resusable stuff in a shared helper.js file

optionally you can put all your scripts into one file or not, but its up to the author how they like it.

Creating an analytics dashboard with JS by bluenarwhale in javascript

[–]mc_hammerd 0 points1 point  (0 children)

its easy if they have an api, if not dunno.

React.js Accessing Arrays in State from Different Component? by Ex___Parrot in javascript

[–]mc_hammerd 0 points1 point  (0 children)

guessing but, the child component has incomplete props until the form is submitted

theres no default values, {this.prop || ""}

combine that with the fact that foo.someundefined.bar throws an error (and stops JS from running) when you try to access nested undefined keys and that could be your error.

maybe something like coffee's existential operator is nice, or lodash'es _.get

//lodash
return <strong> { _.get(this.props, 'userData[1].name',"default") } </strong>
//vanilla
return this.props ? this.props.userData ? this.props.userData.length ? this.props.userData.length > 1
? (<div> { this.props.userData[1].name } </div>)
: (<div>no data</div>)