Skip to main content

Posts

Showing posts with the label Programming

First post using stackedit

Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit 1 . Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog. Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline! Note: StackEdit is accessible offline after the application has been loaded for the first time. Your local documents are not shared between different browsers or computers. Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel. Switch to another document All your local documents are listed in the document panel. You can switch from one to anoth...

Install latest R (3.2.5) on Debian Jessie

Installing R on Ubuntu/Debian is quite painful, especially when you want to install the latest version. I have no clue why this situation stills for a long time, but this is a way to work around. On terminal: ```bash Appends the CRAN repository to your sources.list file You could replace jessie-cran3 by the newer one Find the correct value at https://cloud.r-project.org/ sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/debian jessie-cran3/" >> /etc/apt/sources.list' Adds the CRAN GPG key, which is used to sign the R packages for security. sudo apt-key adv --keyserver subkeys.pgp.net --recv-key 381BA480 sudo apt-get update sudo apt-get install r-base r-base-dev ``` Installing h2o : ```bash to retrieve curl-config otherwise you may have a problem with RCurl sudo apt-get install libcurl4-gnutls-dev ``` R install.packages ("h2o")

Generating a random number between 1 and 6 using only a function which generate 0 or 1

Suppose you have a function toss, which returns 0 or 1 randomly. Now you need to write a function which uses toss () to generate a random integer number between 1 and 6. The idea is: you toss 3 times, and if the value is outside of first six values, you toss 3 times again. The Python code is following: #suppose we have a function called "toss" which return 0 and 1 randomly #we need to write a function to generate number between 1 and 6 #means 1 <= x <= 6 use only the function "toss" from random import randint def toss (): return randint (0, 1) def generateRandomBetween1And6 (): while (True): sum = 0 for i in range (3): sum += toss () * (2 ** i) if (sum >= 1 and sum <= 6): return sum #test res = [0] * 6 for i in range (10000): num = generateRandomBetween1And6 (); res [num - 1] += 1 for i in range (6): print(str(res[i]) + '\n')

How to check if a linked list is cyclic or not

It is a regular interview question: given a one - direction linked list, how to check if there is a cycle inside the list or not. As usual, you will receive a pointer to the head of the list, and you write a function to return a Boolean value which indicates there is a cycle inside the list or not. The obvious way is creating another list / array to store all the elements of the list you visited, but in some cases it is not possible. You can always use this approach, even in the case the node element has no data but a pointer to the next one. If so, you can just store the pointer (i.e, the address). But of course it is not the intention of the interview. If the interviewer asked you to write an algorithm with time complexity is O(n) or space complexity is O(1), the above approach is not suitable. There is a better algorithm: using two pointers, one fast and one slow. Slow pointer moves one element per iteration, while fast pointer moves two. If they meet, it means there i...

Finding a room of the princess

There is an interview question as following: There are 17 rooms line up from 1 to 17. There is a princess who start at a room, then every night she will move to the room next to the previous one (i.e, she has to move to the left or right room - she cannot say at the same room). You are a beast who has to find the princess to be back a prince. Every night, you can open one and only one room to check if the princess is inside or not. You have 30 nights to find the princess, otherwise ... boom! Below is the number of the room the beast (or the future prince) should follow to check during 30 nights: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 Explaining why it is a good strategy might be an interesting task for the reader. I wrote a small application to simulate this strategy at: http://www.codeskulptor.org/#user38_wKWpYR0yZ3_2.py Probably you cannot run the simulation online, but you can get the Python code and try in your computer.

How to auto indent in vim

For many years, vim still be one of the most common editor for developers. There are (too) many shortcuts and commands for vim to remember, so sometimes it is quite difficult. For auto indent, one feature I feel very important, especially when you copied the code from somewhere: 1G=G 1G: move to the first line =: auto indent G: go to end of file

Computer Science Programming Basics in Ruby

Get this book from Amazon (recommend) Product Details Paperback:  188 pages Publisher:  O'Reilly Media; 1 edition (May 1, 2013) Language:  English ISBN-10:  1449355978 ISBN-13:  978-1449355975 Product Dimensions:  7 x 0.4 x 9.2 inches Editorial Reviews Amazon.com Review Author Ophir Frieder offers insights on his latest book, "Computer Science Programming Basics in Ruby" "Computer Science Programming Basics in Ruby" is timely as many of the world's web sites and applications are built with a framework called Ruby on Rails. The core of that framework is a programming language called Ruby. It turns out that Ruby is an exceptional language with which to teach introductory computer science topics. Hence, a rare combination of thing-that-is-useful, along with thing-that-is-good-to-teach has occurred. Our book is the first to really treat Ruby as a solid introductory programming language with which to teach core computer sci...

OpenGL Programming Guide: The Official Guide to Learning OpenGL, Versions 3.0 and 3.1 (7th Edition)

DOWNLOAD Book Description Publication Date:   July 21, 2009 This is the eBook version of the printed book. If the print book includes a CD-ROM, this content is not included within the eBook version. Please note that this title’s color insert (referred to as “Plates” within the text) is not available for this digital product. OpenGL is a powerful software interface used to produce high-quality, computer-generated images and interactive applications using 2D and 3D objects, bitmaps, and color images. The  OpenGL ® Programming Guide, Seventh Edition ,  provides definitive and comprehensive information on OpenGL and the OpenGL Utility Library. The previous edition covered OpenGL through Version 2.1. This seventh edition of the best-selling “red book” describes the latest features of OpenGL Versions 3.0 and 3.1. You will find clear explanations of OpenGL functionality and many basic computer graphics techniques, such as building and rendering 3D models; inter...

OpenGL Shading Language (3rd Edition)

DOWNLOAD Book Description Publication Date:  July 30, 2009   | ISBN-10:  0321637631  | ISBN-13:  978-0321637635   | Edition:  3 OpenGL ®  Shading Language, Third Edition,  extensively updated for OpenGL 3.1, is the experienced application programmer’s guide to writing shaders. Part reference, part tutorial, this book thoroughly explains the shift from fixed-functionality graphics hardware to the new era of programmable graphics hardware and the additions to the OpenGL API that support this programmability. With OpenGL and shaders written in the OpenGL Shading Language, applications can perform better, achieving stunning graphics effects by using the capabilities of both the visual processing unit and the central processing unit. In this book, you will find a detailed introduction to the OpenGL Shading Language (GLSL) and the new OpenGL function calls that support it. The text begins by describing the syntax and semantics of t...

Windows Phone 7.5 Data Cookbook

DOWNLOAD Product Details Paperback:  224 pages Publisher:  Packt Publishing (October 28, 2011) Language:  English ISBN-10:  1849691223 ISBN-13:  978-1849691222 Over 40 recipes for storing, managing, and manipulating data in Windows Phone 7.5 Mango applications. Simple data binding recipes to advanced recipes for building scalable applications Techniques for managing application data in Windows Phone mango apps On-device data storage, cloud storage and API interaction In Detail Windows Phone 7.5 Mango contains support for apps written in Silverlight or XNA. These apps can store data on the device, and also load and manipulate data from "the cloud" and other web services. This Windows Phone 7.5 Data Cookbook has a range of recipes to help you apply data handling concepts. You will be able to apply the knowledge gained from these recipes to build your own apps effectively. This Windows Phone 7.5 Data Cookbook starts with data bindi...

Windows Phone 7.5: Building Location-aware Applications

DOWNLOAD Product Details Paperback:  148 pages Publisher:  Packt Publishing (July 24, 2012) Language:  English ISBN-10:  1849687242 ISBN-13:  978-1849687249 Build your first Windows Phone application with Location and Maps Overview Understand Location Based Services. Work with Windows Phone Location Service. Understand how Maps work. Create a simple Map application and learn to use Geocoding, Pushpins. Discover Directions with Bing Maps Directions. Build two real-world windows phone applications – using Eventful.com and AOL Patch.com API In Detail Windows Phone 7.5 has met with some great initial reviews from all mobile critics. It is poised to be the '3rd' eco-system for mobile, joining Apple's iOS and Google's Android platform. With Microsoft and Nokia working on multiple devices based on Windows Phone, the platform is a no-brainer enterprise success. Microsoft Office, Email, Skype and a fresh new mobile operating system has be...

Windows Phone 7.5 Unleashed

DOWNLOAD Book Description Publication Date:  March 31, 2012   | ISBN-10:  0672333481  | ISBN-13:  978-0672333484   | Edition:  1 Windows® Phone 7.5 Unleashed is the first comprehensive, start-to-finish developer's guide to Microsoft's brand-new Windows Phone 7.5 ("Mango").   Written by Microsoft MVP and leading WPF/Silverlight innovator Daniel Vaughan, this full-color guide covers everything Microsoft developers need to rapidly build highly competitive Windows Phone 7.5 mobile apps. Vaughan teaches through complete sample apps that illuminate each key concept with fully explained code and real-world context. He presents real-world best practices for building highly functional and attractive Metro interfaces; integrating touch, rich media, and data; testing, profiling, and publishing apps; and more. Throughout, he shares expert insights available in no other book, drawing on his exceptional access to the Windows Phone development ...

Sams Teach Yourself Windows Phone 7 Game Programming in 24 Hours

DOWNLOAD Book Description Publication Date:  November 12, 2011   | ISBN-10:  0672335549  | ISBN-13:  978-0672335549   | Edition:  1 Now, there's a practical, hands-on guide to mastering game development for Windows Phone 7 with Visual C# 2010 and XNA Game Studio 4.0. One step at a time, this book teaches all facets of mobile game development, from design through publishing via Microsoft's Marketplace. Top game development author Jonathan S. Harbour starts with the absolute basics, making Windows Phone game development accessible even to programmers who've never written a game before. Then, one step at a time, he shows how to use Microsoft's free XNA toolset to design and construct high-performance, highly-playable games for the newest Windows Phone 7 devices. Friendly, accessible, and conversational, this book delivers a practical grounding in Windows Phone 7 game development without ever becoming overwhelming or intimidating. Each lesso...

Professional Windows Phone 7 Application Development: Building Applications and Games Using Visual Studio, Silverlight, and XNA

DOWNLOAD Book Description Publication Date:  November 9, 2010   | ISBN-10:  0470891661  | ISBN-13:  978-0470891667   | Edition:  1 A one-of-a-kind book on Windows Phone 7 development While numerous books cover both Silverlight and XNA, there lacks a resource that covers the specifics of Windows Phone 7 development. This book fills that void and shares the specifics of building phone applications and games. You’ll learn how to get started with designing, building, testing, and deploying mobile applications for Windows Phone 7. Working examples used throughout the book cover how to design and layout a Windows Phone 7 application, interact with the device, and even sell your applications. Fills the void in the market for an instructional book on developing applications for Windows Phone 7 Offers an overview of Windows Phone and discusses the necessary tools Explains how to work with multiview applications Addresses tool bars, pickers, ...

Sams Teach Yourself Windows Phone 7 Application Development in 24 Hours

DOWNLOAD Book Description Publication Date:  April 22, 2012   | ISBN-10:  0672335395  | ISBN-13:  978-0672335396   | Edition:  1 Covers Windows Phone 7.5 In just 24 sessions of one hour or less, you’ll learn how to develop mobile applications for Windows Phone 7! Using this book’s straightforward, step-by-step approach, you’ll learn the fundamentals of Windows Phone 7 app development, how to leverage Silverlight or the XNA Framework, and how to get your apps into the Windows Marketplace. One step at a time, you’ll master new features ranging from the new sensors to using launchers and choosers. Each lesson builds on what you’ve already learned, helping you get the job done fast—and get it done right! Step-by-step instructions  carefully walk you through the most common Windows Phone 7 app development tasks. Quizzes and exercises  at the end of each chapter help you test your knowledge. By the Way  notes present interesting...

Learning XNA 4.0: Game Development for the PC, Xbox 360, and Windows Phone 7

DOWNLOAD Book Description Release date:  December 27, 2010   | ISBN-10:  1449394620  | ISBN-13:  978-1449394622   | Edition:  annotated edition Want to develop games for Xbox 360 and Windows Phone 7? This hands-on book will get you started with Microsoft's Xna 4.0 development framework right away -- even if you have no experience developing games. Although Xna includes several key concepts that can be difficult for beginning web developers to grasp,  Learning Xna 4.0  shortens the learning curve by walking you through the framework in a clear and understandable step-by-step format. Each chapter offers a self-contained lesson with illustrations and annotated examples, along with exercises and review questions to help you test your understanding and practice new skills as you go. Once you've finished this book, you'll know how to develop your own sophisticated games from start to finish. Learn game development from 2D animatio...

Windows Phone 7 Silverlight Cookbook

DOWNLOAD Product Details Paperback:  304 pages Publisher:  Packt Publishing (August 25, 2011) Language:  English ISBN-10:  1849691169 ISBN-13:  978-1849691161

Windows Phone 7 Programming for Android and iOS Developers (Wrox Programmer to Programmer)

DOWNLOAD Book Description Publication Date:   August 15, 2011 Learn to develop for the new Windows Phone 7 platform With a special focus placed on the new Windows Phone 7 (WP7) design guidelines and technologies, this reference helps you extend your knowledge so that you can learn to develop for the new WP7 platform. The team of authors presents topic-by-topic comparisons between WP7 and Android and the iPhone, enabling you to learn the differences and similarities between them. This indispensible coverage prepares you for making the transition from programming for Android and the iPhone to programming for the exciting new WP7. Covers the exciting new technology of Windows Phone 7 (WP7) and serves as ideal reference for Android and iPhone developers who are eager to get started programming for the WP7 Zeroes in on the differences between programming for Android and the iPhone, making it much easier for you to learn and practice Offers various real-world program...

Windows Phone 7 XNA Cookbook

DOWNLOAD Book Description Publication Date:   February 16, 2012 Written in a cookbook style, this book offers solutions using a recipe based approach. Each recipe contains step-by-step instructions followed by an analysis of what was done in each task and other useful information. The cookbook approach means you can dive into whatever recipes you want in no particular order. If you are an aspiring programmer with some basic concepts in C# and object-oriented knowledge who wants to create games for Windows Phone 7, this book is for you. This book is also for the experienced programmers want to transfer from Windows or Xbox to the Windows Phone 7 platform. Only basic knowledge of C# and .Net is required.

Beginning PhoneGap

DOWNLOAD Book Description Publication Date:   November 11, 2011 Create cross-platform mobile apps without having to learn a new language! PhoneGap is an open source solution, ideal for web developers wanting to build cross-platform mobile apps without having to learn a new language. Using HTML, CSS, and Javascript, PhoneGap allows you to jump into the mobile world and develop apps for iPhone, Android, and the BlackBerry. Walks you through installing the development software Covers the basics of each of PhoneGap's functional units Introduces various projects you can build with the framework Discusses using HTML, CSS, JavaScript Explores the features accelerameter and compass Examines media, storage and files, camera, contacts, geolocation, and more Within  Beginning PhoneGap , each new chapter builds on the lessons taught in the previous so that by the end of the book, you can have mobile apps up and running! "NOTE: Several significant changes to the ...