Import and initialize
Every module needs to be imported and pygame is no exception. Although we need to call the function pygame.init() for all imported modules in pygame to be initialized properly. If we forget this some modules won't work. The function also returns a tuple of all successfully a...
The METEOR_SETTINGS environment variable can accept JSON objects, and will expose that object in the Meteor.settings object. First, add a settings.json to your app root with some configuration info.
{
"public":{
"ga":{
"account":"UA-XXXXXXX-1"
...
Andrew Mao's solution.
Average Aggregation Queries in Meteor
Meteor.publish("someAggregation", function (args) {
var sub = this;
// This works for Meteor 0.6.5
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
// Your arguments to Mongo's aggregation...
StarryNight contains a small utility that parses an application's .meteor/versions file, and converts it into a Release Manifest.
npm install -g starrynight
cd myapp
starrynight generate-release-json
If you don't wish to use StarryNight, simply copy the contents of your .meteor/versions file i...
After defining an enum using any of the above ways and setting a variable, you can print both the variable's value as well as the corresponding name from the enum for the value. Here's an example:
// Define the enum
var ColorsEnum = { WHITE: 0, GRAY: 1, BLACK: 2 }
Object.freeze(ColorsEnum);
// D...
Sometimes you need to serialize or deserialize some fields in a desired format, for example your backend may use the format "YYYY-MM-dd HH:mm" for dates and you want your POJOS to use the DateTime class in Joda Time.
In order to automatically convert these strings into DateTimes object, y...
To enable or disable a BroadcastReceiver, we need to get a reference to the PackageManager and we need a ComponentName object containing the class of the receiver we want to enable/disable:
ComponentName componentName = new ComponentName(context, MyBroadcastReceiver.class);
PackageManager packageM...
NSMutableArray can be initialized as an empty array like this:
NSMutableArray *array = [[NSMutableArray alloc] init];
// or
NSMutableArray *array2 = @[].mutableCopy;
// or
NSMutableArray *array3 = [NSMutableArray array];
NSMutableArray can be initialized with another array like this:
NSMuta...
An HTTP POST request is sent to a URL of the format: "https://api.twilio.com/2xxx-xx-xx/Accounts/[AccountSid]/Messages.json
The example below uses a alphanumeric string as the sender. At the time of writing a sender ID can only be added through a service request Twlio.
Example Request:
To=&q...
using System;
public class Program
{
public static void Main()
{
var date = new DateTime(2016,12,31);
Console.WriteLine(date.ToString()); //Outputs: 12/31/2016 12:00:00 AM
Console.WriteLine(date.ToShortDateString()); //Out...
std::ifstream src("source_filename", std::ios::binary);
std::ofstream dst("dest_filename", std::ios::binary);
dst << src.rdbuf();
C++17
With C++17 the standard way to copy a file is including the <filesystem> header and using copy_file:
std::fileystem::copy...
Python 2.x2.3
python -m SimpleHTTPServer 9000
Python 3.x3.0
python -m http.server 9000
Running this command serves the files of the current directory at port 9000.
If no argument is provided as port number then server will run on default port 8000.
The -m flag will search sys.path for ...
A stream is closed by sending a closing </stream> tag. After the closing stream tag is sent, no more data should be sent on the stream (even in response to data received from the other party). Before closing the connection, the sending entity should wait for a response </stream> tag to g...
Once a TCP connection is established, the initial stream header is sent by the initiating entity. Similarly, whenever a stream restart is required (eg. after negotiating a security layer such as TLS) a stream header must also be sent:
<?xml version='1.0'?>
<stream:stream
from='juliet...
Displaying all the logs from the default buffer on the Command Line can be accomplished by:
adb logcat
This command will show you all the logs from the device's main buffer. Notice that if you use it for the first time, you'll get a lot of information, an enormous stream of data. So you may want...
docker stop mynginx
Additionally, the container id can also be used to stop the container instead of its name.
This will stop a running container by sending the SIGTERM signal and then the SIGKILL signal if necessary.
Further, the kill command can be used to immediately send a SIGKILL or any ot...