Posts

Showing posts from April, 2017

Algorithm To Implement A Word Cloud Like Wordle

Answer : I'm the creator of Wordle. Here's how Wordle actually works: Count the words, throw away boring words, and sort by the count, descending. Keep the top N words for some N. Assign each word a font size proportional to its count. Generate a Java2D Shape for each word, using the Java2D API. Each word "wants" to be somewhere, such as "at some random x position in the vertical center". In decreasing order of frequency, do this for each word: place the word where it wants to be while it intersects any of the previously placed words move it one step along an ever-increasing spiral That's it. The hard part is in doing the intersection-testing efficiently, for which I use last-hit caching, hierarchical bounding boxes, and a quadtree spatial index (all of which are things you can learn more about with some diligent googling). Edit: As Reto Aebersold pointed out, there's now a book chapter, freely available, that covers this same terri

Generate Random Id Javascript Code Example

Example 1: random id js var ID = function ( ) { // Math.random should be unique because of its seeding algorithm. // Convert it to base 36 (numbers + letters), and grab the first 9 characters // after the decimal. return '_' + Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) ; } ; Example 2: js random id Math . random ( ) . toString ( 36 ) . slice ( 2 ) ; Example 3: javascript generate unique id function uuidv4 ( ) { return 'xxxxxxxx - xxxx - 4xxx - yxxx - xxxxxxxxxxxx' . replace ( / [ xy ] / g , function ( c ) { var r = Math . random ( ) * 16 | 0 , v = c == 'x' ? r : ( r & 0x3 | 0x8 ) ; return v . toString ( 16 ) ; } ) ; } console . log ( uuidv4 ( ) ) ; Example 4: javascript uniqie id function uuid ( ) { return 'xxxxxxxx - xxxx - 4xxx - yxxx - xxxxxxxxxxxx' . replace ( / [ xy ] / g , function ( c ) { var r = Math . random ( ) * 16 | 0 , v = c == 'x' ? r : ( r &am

Convert Yt To Mp4 Code Example

Example 1: youtube mp4 downloader I suggest videovor . com , it's really great and you even get an option to choose if you want the whole video or just the audio ! Example 2: youtube to mp4 ytmp3 . cc is the best by far Example 3: yt to mp4 yt1s . com for mp4 is my recommendation Example 4: youtube to mp4 flvto . biz is great for it

Angular Http Params Code Example

Example 1: angular http request query params request(query) { let params = new HttpParams().set("keyword", query); return this.http.get(`Your_URL`, {params}); } Example 2: angular httpclient query params not working getLogs(logNamespace): Observable { // Setup log namespace query parameter let params = new HttpParams().set('logNamespace', logNamespace); return this._HttpClient.get(`${API_URL}/api/v1/data/logs`, { params: params }) } Example 3: router params angular // Navigate and send Params this.router.navigate(['/users/edit/', user.id]);

Convert Html To Image Using Laravel Code Example

Example: convert html to image laravel $(function() { $("#btnSave").click(function() { html2canvas($("#widget"), { onrendered: function(canvas) { theCanvas = canvas; document.body.appendChild(canvas); // Convert and download as image Canvas2Image.saveAsPNG(canvas); $("#img-out").append(canvas); // Clean up //document.body.removeChild(canvas); } }); });

Create Function From SQL Script By Liquibase

Answer : I think you need to add the endDelimiter clause in the Liquibase tag, based on the documentation found here Below is an example <changeSet author="newbie" id="function_rad2deg" dbms="mysql,h2"> <sqlFile encoding="utf8" path="sql/function_rad2deg.sql" relativeToChangelogFile="true" splitStatements="false" stripComments="false" endDelimiter="\nGO" /> </changeSet> Your SQL file with the above delimiter would then look like DROP FUNCTION IF EXISTS rad2deg; GO CREATE FUNCTION rad2deg(rad DOUBLE) RETURNS DOUBLE BEGIN RETURN (rad * 180 / PI()); END GO Hope this helps With above example there are two problems one is it will not work on h2 and 2 is splitStatements should be true: <changeSet author="me" id="01_functions_mysql" dbms="mysql"> <sqlFile encoding

\bin/python3.6: Bad Interpreter: No Such File Or Director Code Example

Example: bad interpreter: /bin/python3^M: no such file or directory dos2unix FILENAME

Css Text Centered Code Example

Example 1: center text in css .class { text-align: center; } Example 2: css center text /* To center text, you need to use text-align. */ .centerText { text-align: center; /* This puts the text into the center of the screen. */ } /* There are also other things that you can use in text-align: left, right, and justify. Left and right make the test align to the right or left of the screen, while justify makes the text align both sides by spreading out spaces between some words and squishing others. */ Example 3: center text css p { text-align: center; } Example 4: center element in div /* html */ Centering with CSS Text-Align Method Margin Auto Method Absolute Positioning Method /* css */ h1, h3 { text-align: center; } .blue-square-container { text-align: center; } .blue-square { background-color: #0074D9; width: 100px; height: 100px; display: inline-block; }

Alter Table Mysql Add Column After Code Example

Example 1: mysql alter table add column ALTER TABLE vendors ADD COLUMN phone VARCHAR ( 15 ) AFTER name ; Example 2: add column in mysq ALTER TABLE Table_name ADD Email varchar ( 255 ) ; Example 3: insert column after column mysql ALTER TABLE tbl_name ADD COLUMN new_column_name VARCHAR ( 15 ) AFTER existing_column_name ; Example 4: add column in mysq ALTER TABLE Table_name ADD name_column INT ( 255 ) ; Example 5: mysql alter table add column ALTER TABLE table ADD [ COLUMN ] column_name column_definition [ FIRST | AFTER existing_column ] ; Example 6: mysql alter table add column ALTER TABLE table ADD [ COLUMN ] column_name column_definition [ FIRST | AFTER existing_column ] ;

Configure IIS 7.0 To Download APK

Answer : Solution 1: Open the Internet Information Service (IIS) Manager -> Properties Click MIME types New -> type Extension ".apk" and MIME type "application/vnd.android.package-archive" Click Ok and Apply Solution 2: Generally, adding a new MIME type should be all that's required: application/vnd.android.package-archive Solution 3: Add this to the web.config : <system.webServer> <staticContent> <mimeMap fileExtension="apk" mimeType="application/vnd.android.package-archive" /> </staticContent> <system.webServer>

Slick Slider Height Problem Code Example

Example: slickjs height slick-track { display : flex !important ; } .slick-slide { height : auto ; }

Angular 9 Introduced A Global '$localize()' Function That Needs To Be Loaded

Answer : You need to make sure you have the @angular/localize package first: npm install @angular/localize --save Then, import '@angular/localize/init' in your polyfills.ts file just like the error says The best way if you are using Angular CLI is to run ng add @angular/localize It will take care of it automatically Or else import '@angular/localize/init'; to your polyfills.ts Tested with Angular 9 If you have many angular projects in same workspace, running ng add @angular/localize will add import statement import '@angular/localize/init' to polyfills.ts in default Project only,i think this will be fixed in later updates. so you need to add import '@angular/localize/init' manually to polyfills.ts in other projects.

Aggregate/project Sub-document As Top-level Document In Mongo

Answer : When you have many, many fields in the sub-document and occasionally it is updated with new fields, then projection is not a viable option. Fortunately, since 3.4, MongoDB has a new operator called $replaceRoot . All you have to do is add a new stage at the end of your pipeline. db.getCollection('sample').aggregate([ { $replaceRoot: {newRoot: "$command"} }, { $project: {score: 0 } //exclude score field } ]) This would give you the desired output. Note that in case of aggregation (especially after a $group stage) the 'command' document could be an array and could contain multiple documents. In this case you need to $unwind the array first to be able to use $replaceRoot . As you have guessed, $project allows you to do that: db.col.aggregate([ { $project : { _id: "$command._id", name: "$command.name", strike: "$command.strike", duratio

Bootstrap Gride Code Example

Example 1: bootstrap grid <div class= "container" > <div class= "row" > <div class= "col-sm" > One of three columns </div> <div class= "col-sm" > One of three columns </div> <div class= "col-sm" > One of three columns </div> </div> </div> Example 2: bootstrap Grid system The above example creates three equal-width columns on small , medium , large , and extra large devices using our predefined grid classes. Those columns are centered in the page with the parent .container. Breaking it down , here’s how it works : Containers provide a means to center and horizontally pad your site’s contents. Use .container for a responsive pixel width or .container-fluid for width : 100 % across all viewport and device sizes. Rows are wrappers for columns. Each column has horizontal padding ( called a gutter ) for controlling the spa

5 Packages Are Looking For Funding Run `npm Fund` For Details Code Example

Example: 61 packages are looking for funding run `npm fund` for details npm config set fund false --global

Addgroup Vs Groupadd

Answer : On most distribution adduser and addgroup are interactive 'convenience' wrappers around the commands useradd and groupadd . You can find addgroup using the command which addgroup , on my machine (Ubuntu 11.04) this lives in /usr/sbin/addgroup . On my box addgroup is a perl script that prompts for various options (interactively) before invoking the groupadd command. groupadd is usually preferable for scripting (say, if you wan't to create users in batch), whereas addgroup is more user friendly (especially if you are unfamiliar with all the options and flags). Of course addgroup also takes many options via the command when you invoke it, but it is primarily intended as an interactive script. Interestingly on my box addgroup is a symlink to adduser , the script checks the name it was invoked under and performs different actions accordingly. groupadd is more preferable for better cross-linux and sometimes cross-unix systems compatibility. addg

Difference Between Css And Scss Code Example

Example 1: sass vs scss /* Answer to: "sass vs scss" */ /* The basic difference is the syntax. While SASS has a loose syntax with white space and no semicolons, the SCSS resembles more to CSS. SASS stands for Syntactically Awesome StyleSheets. It is an extension of CSS that adds power and elegance to the basic language. There's more differences but too much for me! Fortunately, someone else asked the same question over in StackOverflow! Here's a link to their answer: https://stackoverflow.com/questions/5654447/whats-the-difference-between-scss-and-sass */ Example 2: css vs scss /* Answer to: "css vs scss" */ /* Sass has two syntaxes. The most commonly used syntax is known as “SCSS” (for “Sassy CSS”), and is a superset of CSS3's syntax. ... Inspired by Haml's terseness, it's intended for people who prefer conciseness over similarity to CSS. Instead of brackets and semicolons, it uses the indentation of lines to spe

Poppins -google Fonts Code Example

Example: css poppins font <style> @import url ( 'https://fonts.googleapis.com/css2?family=Poppins:wght@600&display=swap' ) ; </style>

Responsive Table Bootstrap 5 Css Design Code Example

Example 1: responsive table bootstrap 4 <div class= "table-responsive-sm" > <table class= "table" > ... </table> </div> Example 2: responsive bootstrap table <table class= "table" > <thead> <tr> <th scope= "col" >#</th> <th scope= "col" >First</th> <th scope= "col" >Last</th> <th scope= "col" >Handle</th> </tr> </thead> <tbody> <tr> <th scope= "row" > 1 </th> <td>Mark</td> <td>Otto</td> <td>@mdo</td> </tr> <tr> <th scope= "row" > 2 </th> <td>Jacob</td> <td>Thornton</td> <td>@fat</td> </tr> <tr> <th scope= "row" > 3 </th>

Can't Turn Off HtmlUnit Logging Messages

Answer : I too had issues with this.. The answer depends on what logging system commons-logging is using under the hood. (since common-logging is just a wrapper). See the following http://commons.apache.org/proper/commons-logging/guide.html#Configuring_The_Underlying_Logging_System The attribute you mention above (org.apache.commons.logging.simplelog.defaultlog) should only be valid if the simple logger is been used. If you are running on JDK 1.4 or higher however it should default to using the JDK logging. In which case it defaults to using the lib/logging.properties from the JRE install location. In my case I had Log4j in the classpath, so it defaulted to that. To take away the randomness of all this you can explicitly set the Logger yourself. Create a commons-logging.properties file in the classpath and pass in the logger to use e.g. # JDK Logging #org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger # Log4j logging (also required log4j.jar to be in

How To Do Red Font Discord Code Example

Example 1: css discord color guide Default : #839496 ``` NoKeyWordsHere ``` Quote : #586e75 ```brainfuck NoKeyWordsHere ``` Solarized Green : #859900 ```CSS NoKeyWordsHere ``` Solarized Cyan : #2aa198 ```yaml NoKeyWordsHere ``` Solarized Blue : #268bd2 ```md NoKeyWordsHere ``` Solarized Yellow : #b58900 ```fix NoKeyWordsHere ``` Solarized Orange : #cb4b16 ```glsl NoKeyWordsHere ``` Solarized Red : #dc322f ```diff -NoKeyWordsHere ``` Example 2: css discord color guide And here is the escaped Default : #839496 ``` This is a for statement ``` Quote : #586e75 ```bash #This is a for statement ``` Solarized Green : #859900 ```diff + This is a for statement ``` //Second Way to do it ```diff ! This is a for statement ``` Solarized Cyan : #2aa198 ```cs "This is a for statement" ``` ```cs 'This is a for statement' ``` Solarized Blue : #268bd2 ```ini [This is a for statement] ``` //Second Way to do it ```asciidoc = This is a for statement = ``` Solarized Yellow