• Breaking News

    Tuesday, June 4, 2019

    Android: Need help with JobScheduler Ask Programming

    Android: Need help with JobScheduler Ask Programming


    Android: Need help with JobScheduler

    Posted: 04 Jun 2019 06:58 PM PDT

    Hi,

    I've a situation where I want to use job scheduler to fetch data in the background from a Web API every 15 minutes based on a users preferences. However, since job scheduler always runs the first time without delay, it means that if a user were to repeatedly start and cancel the job directly after it has finished they could force the fetch data task to run multiple times without having to wait the 15 minutes.

    I would like to avoid this. However, I am unsure how to go about doing this.

    Any advice would be greatly appreciated. And apologies if I have missed something basic. I'm still very new to this.

    Thanks

    submitted by /u/Dirith
    [link] [comments]

    In Object Oriented Programming, How Are Objects created from the same class kept in memory?

    Posted: 04 Jun 2019 09:19 AM PDT

    I'm always worried that if I make, say, a class that prints multiple enemies in a game, that I won't be able to manage which one is which.

    Specifically, let's say I make multiple enemies but they asexually reproduce with an offspring that will have their traits (speed, health, awareness, aggression) be modified to be 3% different from their parents (perhaps their speed is now 3% faster but with 3% slower health). How does the computer differentiate between all of them? Is it a linked list? a map?

    submitted by /u/tiffambrose
    [link] [comments]

    Languages more popular than Haskell with similar features

    Posted: 04 Jun 2019 03:03 PM PDT

    I am wondering if there are either more popular than Haskell for building Web APIs, or have a strong language interop story (such as using the JVM or .NET), that have the following feature:

    1. The ability to define types as Algebraic Data Types with Haskell-style Type Constructors
    2. The ability to do deep pattern matching/destructuring on those types

    What are the closest languages that meet these criteria?

    submitted by /u/ttwinlakkes
    [link] [comments]

    Pattern for solving concurrency issues

    Posted: 04 Jun 2019 03:52 AM PDT

    Now that asynchronous programming is becoming more important ive seen new problems being solved by waiting. For example

    Object A is a member of Group X
    Querying Object A reveals membership of Group X

    Object A leaves Group X
    Querying Object A still reveals membership of Group X right after leaving because the process of registering the changed has taken more time than querying about Object As membership status.

    As i said, i see this being solved by waiting x ms before re-querying about membership. But my question is if there are more clever mechanisms to solve this? Patterns perhaps.

    submitted by /u/NinRejper
    [link] [comments]

    Is i+=1 faster than i++ ???????

    Posted: 04 Jun 2019 06:32 PM PDT

    hey guys,

    I have noticed some performance benefits on leetcode when replacing i++ with i+=1. Am I tripping or is it quicker?

    submitted by /u/GRIFTY_P
    [link] [comments]

    Need your help in pursuing a career in datascience

    Posted: 04 Jun 2019 12:47 PM PDT

    I'm pursuing my master's in applied statistics now. I still have one year left to be done with my college. I'm interested in learning datascience courses. But I don't know how to proceed further and I am completely new to programming field. Please suggest me how to proceed further and what to learn It would be really helpful if you guys can post links of websites or books or anything that might be helpful.

    submitted by /u/adlurinikhil
    [link] [comments]

    Pre-Processing files and saving in another directory with the same structure as the source directory

    Posted: 04 Jun 2019 12:43 PM PDT

    I have a directory structure as follows:

    data/ AD5 1.wav 2.wav E3 3.wav 4.wav E4 5.wav 6.wav H2 7.wav 8.wav 

    I apply some pre-processing steps which split these audio files into several more audio files. So after applying these steps on these audio files, I would like to either:

    • create another directory like PreProcessed_data with the same structure as that of source directory, but with all the populated files. For eg., Pre-Process 1.wav and store the pre-processed files in PreProcessed_data.

    data/ AD5 1.wav 2.wav E3 3.wav 4.wav E4 5.wav 6.wav H2 7.wav 8.wav PreProcessed_data/ AD5 1_1.wav 1_2.wav 1_3.wav 1_4.wav ... 2_1.wav 2_2.wav 2_3.wav ... E3 3_1.wav ... and so on 
    • pick up the first AD5 folder and it's first file 1.wav, pre-process it so that the same folder gets populated with more files as mentioned and delete 1.wav, next then pick up 2.wav and proceed in the same manner.

    The following code tries to do what I mentioned in the first step, but it actually keep saving files in the top-level directory (i.e., in the data directory):

    def make_chunks(filename, chunk_size, sampling_rate, target_location): f = AudioSegment.from_wav(filename) j=0 if not os.path.exists(target_location): os.makedirs(target_location) os.chdir(os.getcwd()) while len(f[:]) >= chunk_size*1000: chunk = f[:chunk_size*1000] chunk.export(target_location+filename[:-4]+"_" + str(j) + ".wav", format ="wav") print("File stored at "+ target_location+filename[:-4]+"_" + str(j)+ ".wav") f = f[chunk_size*1000:] j += 1 if 0 < len(f[:]) and len(f[:]) < chunk_size*1000: silent = AudioSegment.silent(duration=chunk_size*1000) paddedData = silent.overlay(f, position=0, times=1) paddedData.export(target_location+filename[:-4]+"_" + str(j) + ".wav", format ="wav") print("File stored at "+ target_location+filename[:-4] +"_" + str(j)+ ".wav") for dirs, subdirs, files in os.walk(file_path): #file_path = data for i, file in enumerate(files): if file.endswith(('.wav', '.WAV')): print(f"Making chunks of size {chunkSize}s of file: {file}") # Make chunks of data of chunk_size input_file = f"{dirs}" + str("/") + file make_chunks(input_file, chunkSize, sampling_rate, output_path) 

    Is the second step more efficient to implement or the first?

    Any help would be appreciated

    submitted by /u/ZER_0_NE
    [link] [comments]

    Best pattern for exposing microservices to a public API.

    Posted: 04 Jun 2019 06:49 AM PDT

    I have been tasked with creating several microservices for use internally on company projects. Microservices are new to me but I have done some research and come up with a basic plan.

    The microservice will be an asp.net core application running in a docker container. It will basically be a loop that dequeues messages from a rabbitMQ message queue. This should mean that the container can be managed in kubernetes and more workers (containers) spawned as needed to process the queue. Then any of our internal software just needs to access rabbitMQ and it can benefit from the functionality of the microservice.

    Our plan is to also expose these microservices to the general public, either through free API or credit based API. This is where I hit a wall and don't know how to merge the two systems.

    The message queue approach basically sends a message and then the calling service defines a callback for when the task is complete. This is an asynchronous process. Most consumer facing API though work synchronously. A http call is made and connection stays open until the task is complete and then the response is made.

    I am not sure whether to keep the connection open until message is processed or maybe return a token of some sort that the user can use to check status of request. I feel like most people wouldn't like that as it adds extra complexity and it isn't typically what APIs do.

    I have googled the issue and most articles are written about enterprise architecture that is a lot more complicated than the scale we will be operating on and only cover a high level of the architecture. I can't find any practical examples of what an asynchronous API should look like or how to create a synchronous API to interface with a message queue.

    Can someone give me some advice on how I should structure the public facing API?

    submitted by /u/Mr_Nice_
    [link] [comments]

    Help replacing underscores from start of key in JSON.

    Posted: 04 Jun 2019 03:21 AM PDT

    So, basically I'm trying to replace the _ appearing at the start of a key in JSON.

    Regex (so far): _(\w+|\d+){0}

    Test string: {"_latitude":46.0,"_locationAddress":"Russia, Kalmykia","_longitude":45.0,"_msg":"Fresh Location.","_status":true}

    but the problem is the following underscores are also matched (underscores in middle):

    Test string: {"_lat_itude":46.0,"_locationAddress_test":"Russia, Kalmykia","_longitude_value":45.0,"_msg":"Fresh Location.","_status":true}

    Any help will be greatly appreciated. Thank you!

    P.S. I don't know much about Reg-Ex

    submitted by /u/xyzndev
    [link] [comments]

    Where to find research on building a successful development team structure?

    Posted: 04 Jun 2019 12:23 PM PDT

    Not sure if this is the right subreddit or not, but I figured I may as well start here (not sure I like the title, even). I'm hoping to find existing research on how different companies have successfully cross-trained and built up development teams working across different architectures (or if that's even a good goal to begin with).

    The company I'm currently working for has a number of products spread across different platforms (legacy Windows application, mobile applications, and now Web-based cloud applications). Our goal is to be able to support our legacy applications and grow our future-facing applications while at the same time reducing our bus factor, since we only have 1-2 specialists per product, and in a few cases they are the only ones keeping those products alive (though from the outside those products are still widely used).

    submitted by /u/ISeeDevPeople
    [link] [comments]

    How come we use a Database.ini config file?

    Posted: 04 Jun 2019 10:17 AM PDT

    Hello all,

    I am learning PostGres and integrating python with PostGres and one of the tutorials (this one: http://www.postgresqltutorial.com/postgresql-python/connect/) asks me to create a database.ini config file. So my question is what actually is a .ini file and why do we use all this and a python config function rather than just putting all the parameters in a separate python file and importing it?

    submitted by /u/nealgopani
    [link] [comments]

    Can someone help me identify this JSON-like data format?

    Posted: 04 Jun 2019 10:15 AM PDT

    I have a proprietary program that saves and processes 3D spatial data derived from laser scans, and associated with every scan file are a variety of parameters and values. For example, the program saves the tilt and rotation axis of the scanner device as a vector, and so on.

    This data is easy to export, but it comes out as an unhelpfully-labeled .txt file. It looks kinda like JSON, but not quite, and reading it into python or anything else has proved challenging just because I don't recognize what it is, and can't seem to get the right keyword to find the answer on google.

    I'll provide a small clip here that gives the gist of it:

    AttrContainer { Attr<String> { Name "Name" Value "ScannerParam" } Attr<int> { Name "Layer" Value 3 } Attr<int> { Name "NumRows" Value 1367 } 

    Some other clues: there are other headings later on called 'SubContainer's and the data types range from String, int, double and more familiar ones to a variety of vector datatypes I don't recognize.

    Thanks for any help!

    submitted by /u/ericnoshoes
    [link] [comments]

    Should I port to iOS or rewrite entirely in Flutter?

    Posted: 04 Jun 2019 10:03 AM PDT

    I did some freelance work for a client over a year ago where I had to create an Android app & backend for an exercise recommendations theme. Since then, they have come back to me for a new phase of development, and are asking for some new features for the Android app, as well as create an iOS version of it.

    As you've probably read the title, I'm not sure of whether to rewrite in Flutter or patch up the existing Android app and create the iOS version of it. I have a beginner's knowledge of creating apps in Swift, and no experience with Flutter yet. The app itself is pretty simple and the backend takes care of any data crunching needed in the app. The responsibilities of the app are to make network calls, to allow sign in/account recovery, and to show an exercise diary and any relevant meta data/recommendations/tips/feedback. The UI of the app will be changed a lot, so it's only some core functionality that will be retained. There are 10 screens at present, and this is set to expand to about 15 screens from designs.

    submitted by /u/earwax_man
    [link] [comments]

    Google's new device notification can be used for other purposes?

    Posted: 04 Jun 2019 09:03 AM PDT

    Hello,

    English is not my native language so I apologize for any mistake.

    When I login on my google account in a new device I get a "full screen notification" (white background, with IP etc) saying if it's me or not that is trying to access my account.

    I don't know how that type of notification is called, but can it be used for other purposes? For example, sending an OTP from my web service to the user's mobile phone and popping up like that?

    Thank you in advance and sorry if my question is dumb

    submitted by /u/Flawlesspringle
    [link] [comments]

    How to make a program that keep logs for the trending YouTube's video ?

    Posted: 04 Jun 2019 08:38 AM PDT

    Can you please help me figure what i need for this ? I mean what programming language is more suitable ( python i guess ) ? And how i can fetch data from YouTube API ?

    I have some experience with programming in java and C and others , but i am clueless about this task

    in case you're asking i want To analyze what factors affect what videos goes to the trending page in my country.

    Thank you in advance for any help you can give

    submitted by /u/DEMOR01
    [link] [comments]

    How to come up with project ideas?

    Posted: 03 Jun 2019 11:06 PM PDT

    I'm honestly so bad at coming up with project ideas. Not only this, but when I think of something cool, I always back out because I think it might be "too hard". How do I get out of this mindset and begin learning through personal projects?

    submitted by /u/YouWontYouveChanged
    [link] [comments]

    Best way to do Offline First app, that can handle Offline only?

    Posted: 04 Jun 2019 07:50 AM PDT

    I'm working on rebuilding my app in React Native to add accounts for online sync, backup, etc.

    Current users (~6K, Android, offline, no account) would like these features, but I also want to keep offering the option to stay offline without an account.

    We had a hackaton with our company (10 devs) rebuilding the app in React Native (Apollo, GraphQL, Litsor) to aim for this Offline First approach. We had online working, but when we started working on the offline parts, it became complex quickly.

    So the question is; what would be the smartest way forward? Our current strategy is now to first build the app 'offline only' with SQLite. Then add the 'backup' feature where you just upload all your database to the server, or 'reset' by downloading it all from the server. This postpones the sync features, and gives us time to make progress, while we figure out how to tackle that.

    I wrote an article that provides context:
    https://medium.com/idea-growr/rebuilding-idea-growr-offline-first-using-react-native-graphql-docker-during-our-hackaton-576b6f7a8b90

    submitted by /u/IdeaGrowr
    [link] [comments]

    I'm trying to figure out how to run a script. Anyone have knowledge on python and Skyrim? Script I'm trying to run is attached. I'm aware I need to unpack the bsa's but from there I'm lost.

    Posted: 04 Jun 2019 05:05 AM PDT

    How to spend 9000 € as an aspiring software developer?

    Posted: 04 Jun 2019 04:55 AM PDT

    Its easy to explain. I'm sysadmin in military and my duty ends in 2 years. We have a service to spend money for education. How would you spend it?

    submitted by /u/knzbrt
    [link] [comments]

    How do I edit my instructors HTML/JS Pong game

    Posted: 04 Jun 2019 04:34 AM PDT

    Hey there and in advance I appreciate the help from anyone. I've already completed the assignment and I am working on some extra credit adding a score board, start / stop button and sounds. So I am extremely new to JS and just started. Everything I have learned is from CodeCademy and youtube videos. I am having trouble figuring out how to implement things into his code as it is so different than any example I have seen.

    Any time I create a new var for anything like a user score, ai score the game disappears. I've tried using functions / ctx to draw numbers for score board.

    My thought process is I need to define a variable for user / ai score. be able to call it in a function? then create some kind of collision detection to update the score variable. Again any time I start to work I can't figure out, based on his code, where to put variables, where to put functions, where to write it in general. I kinda understand how he wrote this but I don't really see how to edit like I have seen in tutorial videos.

    Thanks again for any knowledge.

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Pong</title> <!-- Basic styling, centering the canvas --> <style> canvas { display: block; position: absolute; margin: auto; top: 0; bottom: 0; left: 0; right: 0; background-color: blue; } </style> </head> <body> <script> var /** * Constants */ WIDTH = 700, HEIGHT = 600, pi = Math.PI, UpArrow = 38, DownArrow = 40, /** * Game elements */ canvas, ctx, keystate, /** * The player paddle * * @type {Object} */ player = { x: null, y: null, width: 20, height: 100, /** * Update the position depending on pressed keys */ update: function() { if (keystate[UpArrow]) this.y -= 7; if (keystate[DownArrow]) this.y += 7; // keep the paddle inside of the canvas this.y = Math.max(Math.min(this.y, HEIGHT - this.height), 0); }, /** * Draw the player paddle to the canvas */ draw: function() { ctx.fillRect(this.x, this.y, this.width, this.height); } }, /** * The ai paddle * * @type {Object} */ ai = { x: null, y: null, width: 20, height: 100, /** * Update the position depending on the ball position */ update: function() { // calculate ideal position var desty = ball.y - (this.height - ball.side)*0.5; // ease the movement towards the ideal position this.y += (desty - this.y) * 0.1; // keep the paddle inside of the canvas this.y = Math.max(Math.min(this.y, HEIGHT - this.height), 0); }, /** * Draw the ai paddle to the canvas */ draw: function() { ctx.fillRect(this.x, this.y, this.width, this.height); } }, /** * The ball object * * @type {Object} */ ball = { x: null, y: null, vel: null, side: 20, speed: 12, /** * Serves the ball towards the specified side * * @param {number} side 1 right * -1 left */ serve: function(side) { // set the x and y position var r = Math.random(); this.x = side===1 ? player.x+player.width : ai.x - this.side; this.y = (HEIGHT - this.side)*r; // calculate out-angle, higher/lower on the y-axis => // steeper angle var phi = 0.1*pi*(1 - 2*r); // set velocity direction and magnitude this.vel = { x: side*this.speed*Math.cos(phi), y: this.speed*Math.sin(phi) } }, /** * Update the ball position and keep it within the canvas */ update: function() { // update position with current velocity this.x += this.vel.x; this.y += this.vel.y; // check if out of the canvas in the y direction if (0 > this.y || this.y+this.side > HEIGHT) { // calculate and add the right offset, i.e. how far // inside of the canvas the ball is var offset = this.vel.y < 0 ? 0 - this.y : HEIGHT - (this.y+this.side); this.y += 2*offset; // mirror the y velocity this.vel.y *= -1; } // helper function to check intesectiont between two // axis aligned bounding boxex (AABB) var AABBIntersect = function(ax, ay, aw, ah, bx, by, bw, bh) { return ax < bx+bw && ay < by+bh && bx < ax+aw && by < ay+ah; }; // check againts target paddle to check collision in x // direction var pdle = this.vel.x < 0 ? player : ai; if (AABBIntersect(pdle.x, pdle.y, pdle.width, pdle.height, this.x, this.y, this.side, this.side) ) { // set the x position and calculate reflection angle this.x = pdle===player ? player.x+player.width : ai.x - this.side; var n = (this.y+this.side - pdle.y)/(pdle.height+this.side); var phi = 0.25*pi*(2*n - 1); // pi/4 = 45 // calculate smash value and update velocity var smash = Math.abs(phi) > 0.2*pi ? 1.5 : 1; this.vel.x = smash*(pdle===player ? 1 : -1)*this.speed*Math.cos(phi); this.vel.y = smash*this.speed*Math.sin(phi); } // reset the ball when ball outside of the canvas in the // x direction if (0 > this.x+this.side || this.x > WIDTH) { this.serve(pdle===player ? 1 : -1); } }, /** * Draw the ball to the canvas */ draw: function() { ctx.fillRect(this.x, this.y, this.side, this.side); } }; /** * Starts the game */ function main() { // create, initiate and append game canvas canvas = document.createElement("canvas"); canvas.width = WIDTH; canvas.height = HEIGHT; ctx = canvas.getContext("2d"); document.body.appendChild(canvas); keystate = {}; // keep track of keyboard presses document.addEventListener("keydown", function(evt) { keystate[evt.keyCode] = true; }); document.addEventListener("keyup", function(evt) { delete keystate[evt.keyCode]; }); init(); // initiate game objects // game loop function var loop = function() { update(); draw(); window.requestAnimationFrame(loop, canvas); }; window.requestAnimationFrame(loop, canvas); } /** * Initatite game objects and set start positions */ function init() { player.x = player.width; player.y = (HEIGHT - player.height)/2; ai.x = WIDTH - (player.width + ai.width); ai.y = (HEIGHT - ai.height)/2; ball.serve(1); } /** * Update all game objects */ function update() { ball.update(); player.update(); ai.update(); } /** * Clear canvas and draw all game objects and net */ function draw() { ctx.fillRect(0, 0, WIDTH, HEIGHT); ctx.save(); ctx.fillStyle = "#fff"; ball.draw(); player.draw(); ai.draw(); // draw the net var w = 4; var x = (WIDTH - w)*0.5; var y = 0; var step = HEIGHT/20; // how many net segments while (y < HEIGHT) { ctx.fillRect(x, y+step*0.25, w, step*0.5); y += step; } ctx.restore(); } // start and run the game main(); </script> </body> </html> 
    submitted by /u/Allieriume
    [link] [comments]

    Cmd language question

    Posted: 04 Jun 2019 12:47 AM PDT

    Is the cmd programming language special? Or can I use cmd with other languages? I'm new and I have not started yet

    submitted by /u/Anony951
    [link] [comments]

    Microsoft VisualStudio subscription to get keys for Server OS?

    Posted: 04 Jun 2019 12:46 AM PDT

    We are a very small company, with a very small budget. I inherited an Exchange 2011 and 15 machines with Office 2010 that staff uses. Inbetween developing I have to keep this hairy old bastard of a system running. I've seen that MS has an Enterprise VS subscription (which we can afford for 2 months).

    If we subscribe, and claim the keys I need (SQL, Svr2016, Exchange, not office though), and then not continue the subscription after a few months, will the software install with those claimed keys be deactivated?

    submitted by /u/blueant1
    [link] [comments]

    No comments:

    Post a Comment