Posts

Showing posts from January, 2008

Can I Print Debug Messages To The Browser Console In Ruby On Rails?

Answer : Simple. Just call puts 'your debug message' and it will be printed to where the server is logging. For instance, if you are running the rails server only by running rails s on a terminal, the output of puts will be on this same terminal. If you need more 'power' to debug, you should consider using IDE's like RubyMine to debug your code. Thus, you can place breakpoints and see all the application state. You can use console.log() in your views: #view.html.erb <script> console.log("Message"); </script> If you want to log in your Model, try: Rails.logger.debug "message!!"

Can An Optical Mouse Be Used To Measure Distance Down To 1-10μm?

Answer : I have tried this before, using an Avago sensor harvested from an optical mouse. It doesn't work. The resolution is excellent but the accuracy is terrible. And the calibration varies with distance from material to the sensor. I arranged a test with a 3" diameter wheel and the sensor reading the outside "tread" of the wheel. I also put a flag on the wheel, passing through an optical interrupter sensor. The number of counts read per revolution varied by a few tenths of a percent, nowhere near good enough repeatability for machining. I guess you could use the optical mouse sensor in combination with an accurate but low-resolution sensor to fill in the in-between points. But really, I think other sensor technologies are more appropriate for this. Neat idea. I considered using a hacked Livescribe pen with special dot rails for the same purpose, then an absolute location would be provided, rather than the relative location a basic optical mouse wou

Can Someone Explain In Simple Terms To Me What A Directed Acyclic Graph Is?

Answer : graph = structure consisting of nodes, that are connected to each other with edges directed = the connections between the nodes (edges) have a direction: A -> B is not the same as B -> A acyclic = "non-circular" = moving from node to node by following the edges, you will never encounter the same node for the second time. A good example of a directed acyclic graph is a tree. Note, however, that not all directed acyclic graphs are trees. dots with lines pointing to other dots I see lot of answers indicating the meaning of DAG (Directed Acyclic Graph) but no answers on its applications. Here is a very simple one - Pre-requisite graph - During an engineering course every student faces a task of choosing subjects that follows requirements such as pre-requisites. Now its clear that you cannot take a class on Artificial Intelligence[B] without a pre requisite course on Algorithms[A]. Hence B depends on A or in better terms A has an edge directed to B. So

Cursor Color Css Code Example

Example: how to hange the color of your cursor in css input { caret-color : red ; }

Conda Install Django Code Example

Example 1: conda install keras conda install - c conda - forge keras Example 2: django in conda paste this command and hit enter : conda install - c anaconda django Copy . Check the Django version by . python - m django - - version Copy . Create a Django project . django - admin startproject mysite Copy . Run the Django server . python manage . py runserver Copy . Example 3: conda import django conda install - c anaconda django Copy Example 4: anconda install django conda install - c anaconda django

Create Angular Cli Version Check Code Example

Example 1: how to check for angular cli version ng --version Example 2: create angular project cli version 8 #Angular 2:the last RC version before switching to angular 4 as far as I can tell — based on this and the next version now depends on angular npm install @angular/cli@1.0.0-rc.2 ng new angular2app #Angular 4: the last CLI version before angular 5 npm install @angular/cli@1.4.10 ng new angular4app #Angular 5: the last CLI version before 6 npm install @angular/cli@1.7.4 ng new angular5app #Angular 6: the last CLI version before 7 npm install @angular/cli@6.2.9 ng new angular6app # Angular 7: (the last CLI version before 8 npm install @angular/cli@7.3.9 ng new angular8app #Angular 8: the last CLI version before 9 npm install @angular/cli@8.3.25 ng new angular8app #Angular 9: not last CLI version 9 npm install @angular/cli@9.1.12 ng new Angular9App

Best Online Converter Youtube To Mp3 Code Example

Example 1: youtube mp3 converter You can use WebTools , it's an addon that gather the most useful and basic tools such as a synonym dictionary , a dictionary , a translator , a youtube convertor , a speedtest and many others ( there are ten of them ) . You can access them in two clics , without having to open a new tab and without having to search for them ! - Chrome Link : https : //chrome.google.com/webstore/detail/webtools/ejnboneedfadhjddmbckhflmpnlcomge/ Firefox link : https : //addons.mozilla.org/fr/firefox/addon/webtools/ Example 2: youtube download mp3 I use https : //github.com/ytdl-org/youtube-dl/ as a Python CLI tool to download videos

Left Rotation Of Array In Python Hackerrank Solution Code Example

Example: arrays left rotation hackerrank solution int n , d ; cin >> n ; int a [ n ] ; cin >> d ; for ( int i = 0 ; i < n ; cin >> a [ i ] , i ++ ) ; d = d % n ; for ( int i = d ; i < n ; i ++ ) cout << a [ i ] << " " ; for ( int i = 0 ; i < d ; i ++ ) cout << a [ i ] << " " ; return 0 ;

Create Row Every After 2 Item In Angular Ng-repeat - Ionic Grid

Answer : I managed to do it using $even . <div ng-repeat="number in numbers"> <div class="row" ng-if="$even"> <div class="col col-50">{{numbers[$index]}}</div> <div class="col col-50">{{numbers[$index + 1]}}</div> </div> </div> Here's a working JSFiddle. The solution from @Patrick Reck is excellent, but it forces you to repeat your code twice, I suggest this improvement: <div ng-repeat="number in numbers"> <div class="row" ng-if="$even"> <div class="col col-50" ng-repeat="num in [numbers[$index],numbers[$index + 1]]"> {{num}} </div> </div> </div> this way you will write your code one time as if it is a normal ng-repeat You can add flex-wrap: wrap to class row http://jsfiddle.net/0momap0n/99/

How To Avoid Horizontal Scroll In Web Page Code Example

Example 1: DISABLE the Horizontal Scroll html , body { max-width : 100 % ; overflow-x : hidden ; } Example 2: how to stop a page from scrolling horizontally overflow-x : hidden Example 3: css how to prevent horizontal scrolling body { overflow-x : hidden !important ; } .container { max-width : 100 % !important ; overflow-x : hidden !important ; }

How Does The Smooth Damp Work In Unity? Code Example

Example: unity smooth damp // Smooth towards the target using UnityEngine ; using System . Collections ; public class ExampleClass : MonoBehaviour { public Transform target ; public float smoothTime = 0.3F ; private Vector3 velocity = Vector3 . zero ; void Update ( ) { // Define a target position above and behind the target transform Vector3 targetPosition = target . TransformPoint ( new Vector3 ( 0 , 5 , - 10 ) ) ; // Smoothly move the camera towards that target position transform . position = Vector3 . SmoothDamp ( transform . position , targetPosition , ref velocity , smoothTime ) ; } }

20 Minutes Alarm Code Example

Example 1: 20 minute timer for good eyesight every 20 minutes look out the window at something 20 feet away for 20 seconds Example 2: 20 minute timer For the 20/20/20 rule you can also close your eyes for 20 seconds and get the same results because it relaxes the mucles in your eyes.