You can set the opacity to a certain UIColor without creating a new one using the init(red:_,green:_,blue:_,alpha:_) initializer.
Swift
let colorWithAlpha = UIColor.redColor().colorWithAlphaComponent(0.1)
Swift 3
//In Swift Latest Version
_ colorWithAlpha = UIColor.red.withAlphaComponent(0.1)...
This code example creates a TCP client, sends "Hello World" over the socket connection, and then writes the server response to the console before closing the connection.
// Declare Variables
string host = "stackoverflow.com";
int port = 9999;
int timeout = 5000;
// Create ...
After receiving the arguments, you can print them as follows:
int main(int argc, char **argv)
{
for (int i = 1; i < argc; i++)
{
printf("Argument %d: [%s]\n", i, argv[i]);
}
}
Notes
The argv parameter can be also defined as char *argv[].
argv[0] may co...
To split one component off of the path:
>>> p = os.path.join(os.getcwd(), 'foo.txt')
>>> p
'/Users/csaftoiu/tmp/foo.txt'
>>> os.path.dirname(p)
'/Users/csaftoiu/tmp'
>>> os.path.basename(p)
'foo.txt'
>>> os.path.split(os.getcwd())
('/Users/csafto...
You can commit changes made to specific files and skip staging them using git add:
git commit file1.c file2.h
Or you can first stage the files:
git add file1.c file2.h
and commit them later:
git commit
The simplest use case is using the subprocess.call function. It accepts a list as the first argument. The first item in the list should be the external application you want to call. The other items in the list are arguments that will be passed to that application.
subprocess.call([r'C:\path\to\a...
To assign variables from the command-line, -v can be used:
$ awk -v myvar="hello" 'BEGIN {print myvar}'
hello
Note that there are no spaces around the equal sign.
This allows to use shell variables:
$ shell_var="hello"
$ awk -v myvar="$shell_var" 'BEGIN {print m...
Rcpp features two functions that enable code compilation inline and exportation directly into R: cppFunction() and evalCpp(). A third function called sourceCpp() exists to read in C++ code in a separate file though can be used akin to cppFunction().
Below is an example of compiling a C++ function w...
git checkout --orphan new-orphan-branch
The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.
source
Actually you can use ReactJS's components in Typescript as in facebook's example. Just replace 'jsx' file's extension to 'tsx':
//helloMessage.tsx:
var HelloMessage = React.createClass({
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
ReactDOM.rende...
This is an extension of Basic Example:
Basic Structure
import React, { Component } from 'react';
import { render } from 'react-dom';
class FirstComponent extends Component {
render() {
return (
<div>
Hello, {this.props.name}! I am a FirstCompon...
There are multiple threads in your code and you need to safely communicate between them.
You can use a Queue from the queue library.
from queue import Queue
from threading import Thread
# create a data producer
def producer(output_queue):
while True:
data = data_computation()
...
You can use git merge --squash to squash changes introduced by a branch into a single commit. No actual commit will be created.
git merge --squash <branch>
git commit
This is more or less equivalent to using git reset, but is more convenient when changes being incorporated have a symbolic...
It is important for someone traversing through the git log to easily understand what each commit was all about. Good commit messages usually include a number of a task or an issue in a tracker and a concise description of what has been done and why, and sometimes also how it has been done.
Better m...
Since Git 1.7.12 it is possible to rebase down to the root commit. The root commit is the first commit ever made in a repository, and normally cannot be edited. Use the following command:
git rebase -i --root
Intents can be used to broadcast messages to other components of your application (such as a running background service) or to the entire Android system.
To send a broadcast within your application, use the LocalBroadcastManager class:
Intent intent = new Intent("com.example.YOUR_ACTION"...
Comparable is one of the most popular modules in Ruby. Its purpose is to provide with convenience comparison methods.
To use it, you have to include Comparable and define the space-ship operator (<=>):
class Rectangle
include Comparable
def initialize(a, b)
@a = a
@b = b
...
To spawn a new process in which you need unbuffered output (e.g. long-running processes which might print output over a period of time rather than printing and exiting immediately), use child_process.spawn().
This method spawns a new process using a given command and an array of arguments. The retu...