Tutorial by Examples: c

The size of a canvas is the area it occupies on the page and is defined by the CSS width and height properties. canvas { width : 1000px; height : 1000px; } The canvas resolution defines the number of pixels it contains. The resolution is set by setting the canvas element width and heigh...
Starter code to create and remove a full page canvas that responds to resize events via javascript. var canvas; // Global canvas reference var ctx; // Global 2D context reference // Creates a canvas function createCanvas () { const canvas = document.createElement(&q...
Many times when working with the canvas you will need to have a canvas to hold some intrum pixel data. It is easy to create an offscreen canvas, obtain a 2D context. An offscreen canvas will also use the available graphics hardware to render. The following code simply creates a canvas and fills it ...
This example will show you how to create a simple animation using the canvas and the 2D context. It is assumed you know how to create and add a canvas to the DOM and obtain the context // this example assumes ctx and canvas have been created const textToDisplay = "This is an example that uses...
There are many situation where you want to draw an image that is rotated, scaled, and translated. The rotation should occur around the center of the image. This is the quickest way to do so on the 2D canvas. These functions a well suited to 2D games where the expectation is to render a few hundred e...
pg_dump -Fc -f DATABASE.pgsql DATABASE The -Fc selects the "custom backup format" which gives you more power than raw SQL; see pg_restore for more details. If you want a vanilla SQL file, you can do this instead: pg_dump -f DATABASE.sql DATABASE or even pg_dump DATABASE > DATABA...
psql < backup.sql A safer alternative uses -1 to wrap the restore in a transaction. The -f specifies the filename rather than using shell redirection. psql -1f backup.sql Custom format files must be restored using pg_restore with the -d option to specify the database: pg_restore -d DATABA...
$ pg_dumpall -f backup.sql This works behind the scenes by making multiple connections to the server once for each database and executing pg_dump on it. Sometimes, you might be tempted to set this up as a cron job, so you want to see the date the backup was taken as part of the filename: $ post...
The datetime module can convert a POSIX timestamp to a ITC datetime object. The Epoch is January 1st, 1970 midnight. import time from datetime import datetime seconds_since_epoch=time.time() #1469182681.709 utc_date=datetime.utcfromtimestamp(seconds_since_epoch) #datetime.datetime(2016, 7, 2...
Angular 2.0.0-rc.4 In this example we'll create a "Hello World!" app with only one root component (AppComponent) for the sake of simplicity. Prerequisites: Node.js v5 or later npm v3 or later Note: You can check versions by running node -v and npm -v in the console/terminal. ...
There are 4 methods for comparing NSDates in Objective-C: - (BOOL)isEqualToDate:(NSDate *)anotherDate - (NSDate *)earlierDate:(NSDate *)anotherDate - (NSDate *)laterDate:(NSDate *)anotherDate - (NSComparisonResult)compare:(NSDate *)anotherDate Consider the following example using 2 dates, N...
To convert NSString to const char use -[NSString UTF8String]: NSString *myNSString = @"Some string"; const char *cString = [myNSString UTF8String]; You could also use -[NSString cStringUsingEncoding:] if your string is encoded with something other than UTF-8. For the reverse path use...
Implicit classes make it possible to add new methods to previously defined classes. The String class has no method withoutVowels. This can be added like so: object StringUtil { implicit class StringEnhancer(str: String) { def withoutVowels: String = str.replaceAll("[aeiou]", &quo...
Think about a situation where we need to callback a function with arguments. std::function used with std::bind gives a very powerful design construct as shown below. class A { public: std::function<void(int, const std::string&)> m_CbFunc = nullptr; void foo() { ...
Assumptions for this example: You have a class, foo.bar.Baz. You'd like to create a run configuration that runs the main method. It's in a module called fooBar. In your gradle file: idea { workspace.iws.withXml { provider -> // I'm not actually sure why this is necessar...
Redirect any naked domain to www.[your_domain].tld: # Start Apache Rewriting engine RewriteEngine On # Make sure you're not already using www subdomain # and that the host string is not empty RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\. # We check for http/https connection ...
qsort :: (Ord a) => [a] -> [a] qsort [] = [] qsort (x:xs) = qsort [a | a <- xs, a < x] ++ [x] ++ qsort [b | b <- xs, b >= x]
Show the changes between the tip of new and the tip of original: git diff original new # equivalent to original..new Show all changes on new since it branched from original: git diff original...new # equivalent to $(git merge-base original new)..new Using only one parameter such as ...
This is the most basic version of a trait in Scala. trait Identifiable { def getIdentifier: String def printIndentification(): Unit = println(getIdentifier) } case class Puppy(id: String, name: String) extends Identifiable { def getIdentifier: String = s"$name has id $id" } ...
Bash indirection permits to get the value of a variable whose name is contained in another variable. Variables example: $ red="the color red" $ green="the color green" $ color=red $ echo "${!color}" the color red $ color=green $ echo "${!color}" the ...

Page 175 of 826