top of page

Results found for ""

  • Create SSIS package in Visual Studio 2017

    In this tutorial, you will learn how to create an SSIS (SQL Server Integration Services) package in Visual Studio 2017 step by step. For this, you need to install SQL Server Data Tools (SSDT) on your machine. SSDT (Business Intelligence template) is used to create SSIS/SSRS/SSAS solutions. For Visual Studio 2018+ Visual Studio 2018 or higher is included with the SSDT BI template so you don't need to install SSDT separately. You just need to check the box "Data Storage and Processing" in the workload section while installing Visual Studio 2018 or later. Visual Studio 2017 Installation Download the older version of Visual Studio from this link. Scroll down on that link to see the older versions. You need to create a Microsoft account (if you don't have one) and have a free Visual Studio subscription. Below is the product description which you need to download. Related: How to file a B1 B2 visa for parents? Download the latest "Community" version (15.9 and not 15.0) to install SSDT BI as highlighted below. VS installation might take 20 to 45 mins depending on your system configuration. If you already have VS 2017 (version 15.0) then you have to upgrade VS 2017 to the latest version. You can go to the Visual Studio Installed version and check for available updates. SSDT BI Installation You can download SSDT (version 15.9.1) from this link. This link might change with new versions coming in the future, in that case, you can simply Google "SSDT release 15.9" and visit the Microsoft VS 2017 SSDT installation page. Related: How to file H4 EAD? Check all the services (SSAS/SSIS/SSRS) as shown below and select Visual Studio Community 2017 from the drop-down list. Click Install. The download and installation process will take around 30 minutes depending on your system configuration. Restart your computer once the installation is completed. Installation Check Once installation is done, open Visual Studio 2017 and go to the menu option File > New Project. Look up 🔎 Business Intelligence, if you can find Integration Services, Analysis Services, and Reporting Services on the left side of the panel, then the installation is fine. Create SSIS package To create the SSIS basic package, you need to Create a project for the package. Add a control flow and data flow to the package. Add components to the data flow. What is SSIS? SSIS is an ETL tool for data warehousing that comes with Microsoft SQL Server. There is no extra cost for SSIS services. It lets you set up automated data load or extract processes to and/or from your SQL Server. SSIS stands for SQL Server Integration Services and ETL stands for Extract-Transform-Load. It is comparable to other ETL tools like Informatica and IBM Datastage etc. What does it do? SSIS provides you platform referred to as SSDT to develop ETL solutions which could be the combination of one or more packages. Solutions are saved with the .sln extension and packages are XML files saved with the .dtsx extension. Packages are deployed in SQL Server MSDB database called SSISDB and managed in the Integration Services Catalog in SSMS (SQL Server Management Studio). Creating Package 1. Go to File > New > Project, and name your project. Click OK. It will open SSIS designer. On the left-hand panel, you will see the SSIS toolbox with all the tasks, and at the center, you will see various tabs to switch between control flow, data flow, parameters, event handler, and package explorer. On the right panel, you will see Solution Explorer where you can find the connection manager. Now, to create an SSIS package you need at least one control flow and a data flow task. A data flow task is simply a task that is used to Extract, Load, and Transform the data, and control flow is like the logical unit that controls the execution of tasks, like the flow in which tasks will execute. 2. Drag and drop the data flow task from the SSIS toolbox to the central panel (control flow tab) like the following: 3. You can double-click on Data Flow Task to rename it. I am keeping it as the default "Data Flow Task". Now right-click on Data Flow Task > Edit, or you can simply select the "Data Flow Task" and click on the "Data Flow" tab, it will open a screen where you can edit your "Data Flow Task". 4. Now drag and drop OLE DB Source, OLE DB Destination, and Data Conversion task from the SSIS toolbox to the designer space as shown below. 5. Select OLE DB Source and drag and drop the blue/green arrow to connect the Data Conversion task. Similarly, drag and drop/green blue arrow (not the red one) from the Data conversion task to OLE DB Destination. 6. Now, you need to create an OLE DB connection for the source and target. For this go to the Solution Explorer panel on the right-hand side > Connection Manager> New Connection Manager. Select OLE DB and click ADD. If you have already created an OLE DB data connection earlier on your machine it will show up here, otherwise, you can click on NEW and create a new one. Just enter your database name and test the connection. I assume you have the AdventureWorks database running on your machine if not please refer to this post. I have already installed SQL Server 2014 and SQL Express so you can see 2 instances of SQL Server service running on my machine. Now, for example, I have chosen the AdventureWorks 2014 database. 7. Now go back to the Data Flow screen and right-click on OLE DB Source task > Edit. Choose a sample table from the drop-down list, [Production].[Product]. Now go to the Columns tab, remove selected columns, and select these five columns - Name, ListPrice, Size, Weight, and SellStartDate and click OK. It's just for example purposes. 8. Now go to Data Flow and right-click on Data Conversion task > Edit. Select the SellStartDate column and change its data type from [DT_DBTIMESTAMP] to [DT_DBDATE], keep the alias name the same, and click OK. Just a minor datatype conversion to showcase this example. 9. Now, right-click on OLE DB destination editor > Edit > New SSIS by default creates the "create table" statement for you with input columns. CREATE TABLE [OLE DB Destination] ( [Name] nvarchar(50), [ListPrice] money, [Size] nvarchar(5), [Weight] numeric(8,2), [OLE DB Source.SellStartDate] datetime, [Data Conversion.SellStartDate] date ) Edit the table name and remove [OLE DB Source.SellStartDate] and hit OK, CREATE TABLE [OLE DB Destination_Products] ( [Name] nvarchar(50), [ListPrice] money, [Size] nvarchar(5), [Weight] numeric(8,2), [Data Conversion.SellStartDate] date ) Mappings should look like this, just click OK. 10. Now right-click on the blue/green arrow between the Data conversion task and the OLE DB Destination task and enable the data viewer. This is not a mandatory step but just to see the data preview after the data conversion. 11. Now hit the START button on top of your screen. This will start the package. You can see SellStartDate has only the date after conversion (no time field), all the tasks are green ticked which means they ran successfully and the number of rows is 1,008 processed. You can stop the flow or restart again from the buttons highlighted on top of the screen. That's it. This package creation example was showcased by Microsoft itself. I haven't modified anything to keep examples simple and informative. I hope you enjoyed the post. If you have any questions please mention them in the comments section below. Thank you. Next: SQL Server 2014 Download and Installation

  • How to clear Google cloud professional data engineer certification exam?

    In this blog you will learn - How to get Google cloud certification? How much it cost to get Google certified? Best Google certification courses available online right now. How to train yourself with Google cloud certification practice exams before actual examination. Before we begin I would like to mention one fact, you can crack this exam even if you don’t have "any work experience or prior knowledge" of GCP (Google Cloud Platform). I am writing this blog to showcase how you can clear Google cloud professional data engineer certification without any prior knowledge of GCP. I would start by dividing this whole preparation into 3 basic sections: Online video lectures (absolutely free if completed within a time frame) Glance through some Google documentation Finally, few practice tests Step 1. Online Video Lectures Coursera: First begin with Coursera course which is also suggested by google and it's really knowledgeable. You can use 7 day free trial of coursera to complete this specialization. But since this is very big course, you will have to devote good amount of time everyday for these 7 days. This course comes with Qwiklabs where you can do lab assessments without creating any GCP account. Also this course comes with quizzes so as to get good understanding of GCP components with hands-on experience as well. Udemy: Next comes Udemy, it's a combined course for both data engineers and architects. This course will help you to understand real world implementation of GCP components. You can skip machine learning part from this course if you want. These two courses are not very exam oriented but will give you good understanding of every GCP component with some basic hands on. Now jumping to exam oriented video lectures, Cloud Academy and Linux Academy comes to our rescue. Both of these sites comes with a 7 days free trial option. Cloud Academy will give you good knowledge of most of the topics covered in the exam. You can learn machine learning from this course. Try to understand well each and every point covered in this course. This course also comes with quizzes for main topics. Understand well the explanations given for the quizzes. However this Cloud Academy course doesn’t cover topics such as data preparation and this is where linux academy comes into the picture. Linux Academy course has covered all the topics of the exam in most exam oriented way. You will get good understanding of machine learning and other remaining topics. This course also has topic wise tests and a full 2 hour test (50 questions) to give you a feel of real test. However I would recommend you to give this test at the last stage of preparation and also attempt this test at least thrice and score 100%. For revision I would suggest you to go through Linux academy’s Data Dossier. This is the best part of complete course which you will require at the last moment. Step 2: Google Documentation There are few topics such as big-query, pub-sub, data-studio for which you will have to go through google docs. For data flow you need to go through apache beam documentation. Understand following points of each of the components very well: Access Control Best practices Limitations For ML, understand well the different use cases where pre-trained ML apis are used. This will help you understand whether to use pre-build apis or to make a custom model. Step 3: Practice Test For practice tests you can go through the following: Google DE practice test Whizlabs Test Linux academy practice test Make sure you give all the tests at least thrice and understand well, each question and their answers. For each of the question you should understand why a particular answer is correct and why the remaining ones are incorrect. At the end I would suggest that google has made this exam very logical where in you need to know the in and out of every topic very well to clear the exam. So understand everything well and don’t try to memorize or mug up everything. Best of luck!!

  • Calling 911 for Pepperoni Pizza Delivery, But Why?

    Phone Conversation of 911 Operator (reference Reddit user Crux1836); Officer : “911, where is your emergency?” Caller : “123 Main St.” Officer : “Ok, what’s going on there?” Caller : “I’d like to order a pizza for delivery.” Officer : “Ma’am, you’ve reached 911” Caller : “Yeah, I know. Can I have a large with half pepperoni, half mushroom and peppers?” Officer : “Ummm… I’m sorry, you know you’ve called 911 right?” Caller : “Yeah, do you know how long it will be?” Officer : “Ok, Ma’am, is everything ok over there? do you have an emergency?” Caller : “Yes, I do.” Officer : “… And you can’t talk about it because there’s someone in the room with you?” Caller : “Yes, that’s correct. Do you know how long it will be?” Officer : “I have an officer about a mile from your location. Are there any weapons in your house?” Caller : “Nope.” Officer : “Can you stay on the phone with me?” Caller : “Nope. See you soon, thanks” (Officer) As we dispatch the call, I check the history at the address, and see there are multiple previous domestic violence calls. The officer arrives and finds a couple, female was kind of banged up, and boyfriend was drunk. Officer arrests him after she explains that the boyfriend had been beating her for a while. I thought she was pretty clever to use that trick. Definitely one of the most memorable calls. Another case which happed in UK ; The call went something like this: Operator : Police Emergency Caller : Hello, I’d like to order a curry please. Operator : You’re through to the police Caller : Could you deliver it to ‘123 Street’ Operator : Madam, this is the police, not a delivery service Caller : Could you deliver it as soon as possible? Operator : (starting to realize something is fishy) “Madam, are you in a situation where you cannot talk freely? Caller : Yes. Operator : Are you in danger? Caller : Yes. Operator : Okay, I’m arranging help for you immediately. Caller : Could you make it two Naan Breads? My husband is really hungry. Operator : I’ll send two officers. This transcript is purely based on memory from a police officer’s memoir. On the police response, a very angry man was arrested for domestic violence. There was obviously the risk that the operator could have hung up on a ‘time-wasting’ caller, but once they realized something was wrong, they changed scripts immediately. Can you actually call Emergency Services and “order a pizza” as a tactic for help? The answer is "No", there is no such 911 pizza call "code". Police and 911 operators say there’s no such secret code, and that your best option if you’re afraid of someone in the room overhearing your call is to text 911 with your location and the type of emergency. However, a meme has been circulating on social media reads: “If you need to call 911 but are scared to because of someone in the room, dial and ask for a pepperoni pizza… Share this to save a life” Here is what LAPD tweets, Remember, if you can't call - you can TEXT ! Tags: #Funny #Lesson

  • Best Office Prank Ever, Don't Miss the End

    Have you ever seen chocolate thief in your office? This is the epic message chain when someone started to stealing chocolates from office refrigerator. #Funny #Office #Prank

  • A Day in the Life of a Computer Programmer

    As a computer programmer, my daily life is actually kind of weird. I did my undergrad in computer science and worked with Microsoft for 4 years. I'm self taught and have spent a far greater amount of hours learning how to code. I work on US based client projects. Due to different time zone, my hours are not fully standard. Usually I try to work 7–9 hours a day, however sometimes it can be as much as 10–12 hours. Here is my routine that I follow roughly everyday, 4:50 am : Alarm beeps, Snooze 1 .. 5:05 am : Snooze 2 .. 5:20 am : Snooze 3 .. 5:35 am : Snooze n, Rolling in bed .. 6:00 am : Semi awake 6:10 am : Check Facebook, Instagram, Whatsapp, Robinhood, 9gag 6:15 am : Wake-up, Workout (pushups, gym, meditation, yoga, I am lying) 6:30 am : Shower, Dress up 7:30 am : Leave for work, Mustang, Daily traffic, Pandora (free subscription) 8:15 am : Arrive at work, Parking, Swipe access card at the entrance 8:20 am : Checking email, Service Now 8:30 am : Offshore-onshore call, Status updates, Discuss target for the day 9:00 am : Breakfast (uncertain) 9:20 am : Code, debug, code, code, debug 10:00 am : Error, error, error, error 11:00 am : Coffee, "Smoking kills" 11:30 am : Code, code, debug, code 12:00 pm - 2:00 pm : Global variable "Lunch" 2:00 pm : Code, debug, code, debug 3:00 pm : Code, code, code, code 3:30 pm : Check on the entire team 4:30 pm : Wrap up, Leave for home, Drive, Traffic, Pandora 5:15 pm : Arrive home, Change dress, Chillax 5:45 pm : Jog for 4-5 miles, Shower 6:30 pm : Facebook, Youtube, News, Blogs 8:00 pm - 9:00 pm : Dinner, Eat 24, Cooking (rare element) 9:30 pm : Offshore-onshore call (sometimes free), Otherwise Netflix 10:00 pm : Netflix, Youtube, Chit-chat with girlfriend 10:30 pm - 11:00 pm : Shut down, Sleep 4:50 am : Alarm beeps, Snooze 1, 2, 3, n .. Thanks for reading, hit like and share if you enjoyed the post!

  • Funny Short Math Jokes and Puns, Math is Fun!

    A mathematical joke is a form of humor which relies on aspects of mathematics or a stereotype of mathematicians to derive humor. The humor may come from a pun, or from a double meaning of a mathematical term, or from a lay person's misunderstanding of a mathematical concept. Instead of good-bye we say Calc-U-later Why should you not mix alcohol and calculus? Because you should never drink and derive. Write the expression for the volume of a thick crust pizza with height "a" and radius "z". The formula for volume is π·(radius)**2·(height). In this case, pi·z·z·a. How do you make seven even? Just remove the “s.” Q: What is a proof? A: One-half percent of alcohol. Q: What is gray and huge and has integer coefficients? A: An elephantine equation. Q: Why do truncated Maclaurin series fit the original function so well? A: Because they are “Taylor” made. Q: What is gray and huge and has integer coefficients? A: An elephantine equation. Q: What’s a polar bear? A: A rectangular bear after a coordinate transform. Q: What do you get if you cross a mosquito with a mountain climber? A: You can’t cross a vector with a scalar. Theorem. 3=4. Proof. Suppose a + b = c This can also be written as: 4a − 3a + 4b − 3b = 4c − 3c After reorganizing: 4a + 4b − 4c = 3a + 3b − 3c Take the constants out of the brackets: 4(a + b − c) = 3(a + b − c) Remove the same term left and right: 4=3 A mathematician and an engineer are on a desert island. They find two palm trees with one coconut each. The engineer shinnies up one tree, gets the coconut, and eats it. The mathematician shinnies up the other tree, gets the coconut, climbs the other tree and puts it there. “Now we’ve reduced it to a problem we know how to solve.” There are a mathematician and a physicist and a burning building with people inside. There are a fire hydrant and a hose on the sidewalk. The physicist has to put the fire out…so, he attaches the hose to the hydrant, puts the fire out, and saves the house and the family. Then they put the people back in the house, set it on fire, and ask the mathematician to solve the problem. So, he takes the hose off the hydrant and lays it on the sidewalk. “Now I’ve reduced it to a previously solved problem” and walks away. Three men are in a hot-air balloon. Soon, they find themselves lost in a canyon somewhere. One of the three men says, “I’ve got an idea. We can call for help in this canyon and the echo will carry our voices far.” So he leans over the basket and yells out, “Helloooooo! Where are we?” (They hear the echo several times.) Fifteen minutes later, they hear this echoing voice: “Hellooooo! You’re lost!!” One of the men says, “That must have been a mathematician.” Puzzled, one of the other men asks, “Why do you say that?” The reply: “For three reasons: (1) He took a long time to answer, (2) he was absolutely correct, and (3) his answer was absolutely useless.” Infinitely many mathematicians walk into a bar. The first says, "I'll have a beer." The second says, "I'll have half a beer." The third says, "I'll have a quarter of a beer." Before anyone else can speak, the barman fills up exactly two glasses of beer and serves them. "Come on, now,” he says to the group, “You guys have got to learn your limits.” Scientists caught a physicist and a mathematician and locked them in separate rooms so both could not interact with each other. They started studying their behavior. The two were assigned a task to remove a hammered nail from inside the wall. The only tools they had were a hammer and a nail-drawer. After some muscular effort, both solved the tasks similarly by using the nail-drawer. Then there was a second task, to remove the nail that was barely touching the wall with its sharp end. The physicist simply took the nail with his hand. The mathematician hammered the nail inside the wall with full force and proudly announced: the problem has been reduced to the previous one! A mathematician organizes a raffle in which the prize is an infinite amount of money paid over an infinite amount of time. Of course, with the promise of such a prize, his tickets sell like hot cake. When the winning ticket is drawn, and the jubilant winner comes to claim his prize, the mathematician explains the mode of payment: "1 dollar now, 1/2 dollar next week, 1/3 dollar the week after that..." Sherlock Holmes and Watson travel on a balloon. They were hidden in clouds, so they didn’t know which country they flew above. Finally they saw a guy below between clouds, so they asked. “Hey, you know where we are?” “Yes” “Where?” “In a balloon”. And the guy was hidden by clouds again. Watson:”Goddamn, what a stupid idiot!” Holmes:”No my friend, he’s a mathematician”. Watson:”How can you know that, Holmes?” Holmes:”Elementary, my dear Watson. He responded with an absolutely correct and absolutely useless answer”. My girlfriend is the square root of -100. She’s a perfect 10, but purely imaginary. How do mathematicians scold their children? "If I've told you n times, I've told you n+1 times..." What’s the best way to woo a math teacher? Use acute angle. What do you call a number that can't keep still? A roamin' numeral. Take a positive integer N. No wait, N is too big; take a positive integer k. A farmer counted 196 cows in 
the field. But when he rounded them up, he had 200. Why should you never argue with decimals? Because decimals always have a point. When someone once asked Professor Eilenberg if he could eat Chinese food with three chopsticks, he answered, "Of course," according to Professor Morgan. How are you going to do it? I'll take the three chopsticks, I'll put one of them aside on the table, and I'll use the other two. A statistics professor is going through security at the airport when they discover a bomb in his carry-on. The TSA officer is livid. "I don't understand why you'd want to kill so many innocent people!" The professor laughs and explains that he never wanted to blow up the plane; in fact, he was trying to save them all. "So then why did you bring a bomb?!" The professor explains that the probability of a bomb being on an airplane is 1/1000, which is quite high if you think about it, and statistically relevant enough to prevent him from being able to fly stress-free. "So what does that have to do with you packing a bomb?" the TSA officer wants to know, so the professor explains. "You see, if there's 1/1000 probability of a bomb being on my plane, the chance that there are two bombs is 1/1000000. So if I bring a bomb, the chance there is another bomb is only 1/1000000, so we are all much safer." The great probabilist Mark Kac (1914-1984) once gave a lecture at Caltech, with Feynman in the audience. When Kac finished, Feynman stood up and loudly proclaimed, "If all mathematics disappeared, it would set physics back precisely one week." To that outrageous comment, Kac shot back with that yes, he knew of that week; it was "Precisely the week in which God created the world." An experimental physicist meets a mathematician in a bar and they start talking. The physicict asks, "What kind of math do you do?" to which the mathematician replies, "Knot theory." The physicist says, "Me neither!" A poet, a priest, and a mathematician are discussing whether it's better to have a wife or a mistress. The poet argues that it's better to have a mistress because love should be free and spontaneous. The priest argues that it's better to have a wife because love should be sanctified by God. The mathematician says, "I think it's better to have both. That way, when each of them thinks you're with the other, you can do some mathematics." Three mathematicians walk into a bar. Bartender asks:”Will all of you guys have beer?” The first mathematician: “I don’t know”. The second mathematician: “I don’t know”. The third one: ”Yes”. A mathematician is attending a conference in another country and is sleeping at a hotel. Suddenly, there is a fire alarm and he rushes out in panic. He also notices some smoke coming from one end of the corridor. As he is running, he spots a fire extinguisher. “Ah!”, he exclaims, “A solution exists!” and comes back to his room and sleeps peacefully. Two statisticians go to hunt a bear. After roaming the woods for a while, they spot a lone grizzly. The first statistician takes aim and shoots, but it hits three feet in front of the bear. The second one shoots next, and it hits three feet behind the bear. They both agree that they have shot the bear and go to retrieve it.. Parallel lines have so much in common. It’s a shame they’ll never meet. I just saw my math teacher with a piece of graph paper. I think he must be plotting something. Are monsters good at math? No, unless you Count Dracula. My girlfriend is the square root of -100. She's a perfect 10, but purely imaginary. Q: Why is a math book depressed? A: Because it has so many problems. How do you stay warm in an empty room? Go into the corner where it is always 90 degrees. There are three kinds of people in the world: those who can count and those who can't. Q: Why did I divide sin by tan? A: Just cos. Q: Where's the only place you can buy 64 watermelons and nobody wonders why? A: In an elementary school math class. 60 out of 50 people have trouble with fractions. But why did 7 eat 9? Because you’re supposed to eat 3 squared meals a day. Q: Why is the obtuse triangle depressed? A: Because it is never right. Q: Why did the 30-60-90 degree triangle marry the 45-45-90 degree triangle? A: Because they were right for each other. Q: Why didn't the Romans find algebra very challenging? A: Because they always knew X was 10. Two statisticians went out hunting and they found a deer. The first one overshoots by 5 meters. The second one undershoots by 5 meters. They both hug each other and shout out “We Got It!” An astronomer, a physicist and a mathematician are on a train traveling from England to Scotland. It is the first time for each of them. Some time after the train crosses the border, the three of them notice a sheep in a field. “Amazing!” says the astronomer. “All the sheep in Scotland are black!”. “No, no” responds the physicist. “Some sheep in Scotland are black!” The mathematician closes his eyes pityingly, and intones: “In Scotland, there is at least one field, containing at least one sheep, at least one side of which is black.” An engineer, a physicist and a mathematician go to a hotel. The boiler malfunctions in the middle of the night and the radiators in each room set the curtains on fire. The engineer sees the fire, sees there is a bucket in the bathroom, fills the bucket with water and throws it over the fire. The physicist sees the fire, sees the bucket, fills the bucket to the top of his mentally calculated error margin and throws it over the fire. The mathematician sees the fire, sees the bucket, see the solution and goes back to sleep. #MathJokes #FunnyMath #MathPuns #ShortMathJoke

  • How can I get the source code of the Python Packages?

    You can find source code on Github. Under cpython you will be able to find all the modules and python objects (written in C). You can also find which file (using __file__ attribute) on your system is used for respective module. For example math and random module, >>> import math >>> import random >>> math.__doc__ 'This module is always available. It provides access to the\nmathematical functions defined by the C standard.' >>> math.__file__ '/Users/Rajput/anaconda/lib/python2.7/lib-dynload/math.so' >>> random.__file__ '/Users/Rajput/anaconda/lib/python2.7/random.pyc' Now, you can get source code for objects written in python (not C) with inspect get source code. You can also refer Python docs for “inspect” library. >>> import inspect >>> inspect.getsourcelines(random) (['"""Random variable generators.\n', '\n', ' integers\n', ' --------\n', ' uniform within range\n', '\n', ' sequences\n', ' ---------\n', ' pick random element\n', ' pick random sample\n', : so on..

  • What does // mean in python?

    It’s floor division. Python docs has very nice documentation on this. Python3: Mathematical division that rounds down to nearest integer. The floor division operator is //. For example, the expression 11 // 4 evaluates to 2 in contrast to the 2.75 returned by float true division. >>> 11//4 2 >>> 11/4 2.75 Note that (-11) // 4 is -3 because that is -2.75 rounded downward. >>> -11//4 -3 >>> -11/4 -2.75 Python2: True division returns round integer in older version of python. Floor division is same. >>> 11//4 2 >>> 11/4 2 >>> -11//4 -3 >>> -11/4 -3

  • What programming language is famous amongst Russians?

    According to Google Trends it seems like Javascript. However, I didn’t except Python as least popular language amongst Russians. First of all, it’s little difficult to cover all the programming languages used by Russians (or used in Russia). But we can find what are the most popular programming languages in Russia and then drill down geographically. Javascript, Java, Python, PHP and C++ are the most popular languages according to Google Trends. I didn’t include Swift, Ruby, Rust, Scala, PERL etc because they are comparatively less popular to show on charts. Geographically, it looks like Javascript is most popular programming language across Russia. Did you notice the blue color in above chart? I didn’t expect this for Python. Interesting. Drilling down just for Javascript “Saint Petersburg” is the most popular location with Javascript in Russia. I haven’t heard this place before, sorry my geography is not very good.

  • What is the most efficient way to find prime factors of a number (python)?

    One of the best method is to use Sieve of Eratosthenes 0 → False 1 → False 2 → True and so on.. Python program is shown below, def primes(n): flag = [True] * n flag[0] = flag[1] = False for (index, prime) in enumerate(flag): if prime: yield index for i in range(index*index, n, index): flag[i] = False Print the last item from generator, p = None for p in is_prime(1000000): pass print(p) >>> 999983 Regular way To make the program efficient you need to: Cross out 1 as it's not prime. Cross out all of the multiples of 2 if input number is odd. Cross out all of the multiples of 3 if input number is even. Most importantly, for number N, you only need to test until you get to a prime till √N. If a number N has a prime factor larger than √N , then it surely has a prime factor smaller than √N. So it's sufficient to search for prime factors in the range [1,√N]. If no prime factors exist in the range [1,√N], then N itself is prime and there is no need to continue searching beyond that range. You can do it like this, def is_prime(num): if num<2: return False else: return all(num%i for i in range(2, int(num ** 0.5)+1)) Checking if 1471 is prime, is_prime(1471) True Let's say you want to check all the prime numbers up-to 2 million, prime_list = [i for i in range(2000000) if is_prime(i)] I have seen similar type of problems in project Euler like sum of primes or total number of primes below (a very large number). If the number is small you can simply divide by all the numbers till (n-1) and check if it’s prime or not, but that program (shown below) performs very bad if the number is big. def is_prime(num): if num < 2: return False for i in range(2, num): if num%i==0: return False else: return True For example: is_prime(47) True >>> %timeit ("is_prime(47)") 10.9 ns ± 0.0779 ns per loop (mean ± std. dev. of 7 runs, 100000000 loops each) Above program performs very bad if the number is big. Better solution is, instead of dividing by all the numbers up-to (n-1), you just need to check if number is divisible till sqrt(num). def is_prime(x): '''Checking if number is prime, run until sqrt(number)''' sqrt = round(x ** 0.5) if x < 2: return False else: for i in range(2, sqrt + 1): if x%i == 0: return False else: return True OR, def is_prime(num): if num<2: return False else: return all(num%i for i in range(2, int(num ** 0.5)+1)) That’s it, now use list comprehension to get prime_list and print whatever you need. >>> prime_list=[i for i in range(3000000) if is_prime(i)] >>> print(f"Number of primes below 3 million: {len(prime_list)}") >>> print(f"Sum of primes below 3 million: {sum(prime_list)}") >>> print(prime_list) Number of primes below 3 million: 216816 Sum of primes below 3 million: 312471072265 [2, 3, 5, 7, 11, 13, 17, 19....... ]

bottom of page