This example creates a new file named "NewFile.txt", then writes "Hello World!" to its body. If the file already exists, CreateFile will fail and no data will be written.
See the dwCreationDisposition parameter in the CreateFile documentation if you don't want the function to fa...
Enum constants are instantiated when an enum is referenced for the first time. Therefore, that allows to implement Singleton software design pattern with a single-element enum.
public enum Attendant {
INSTANCE;
private Attendant() {
// perform some initialization routine
...
To get basic information about a DataFrame including the column names and datatypes:
import pandas as pd
df = pd.DataFrame({'integers': [1, 2, 3],
'floats': [1.5, 2.5, 3],
'text': ['a', 'b', 'c'],
'ints with None': [1, None, 3]})
...
NuGet version
Before you start: make sure your NuGet version is up to date.
In Visual Studio, go to Tools > Extensions and Updates, then Updates > Visual Studio Gallery. Check if there is a NuGet Update available and install it. Or, you can uninstall the existing nuget and reinstall it. It w...
It is possible to detect whether an operator or function can be called on a type. To test if a class has an overload of std::hash, one can do this:
#include <functional> // for std::hash
#include <type_traits> // for std::false_type and std::true_type
#include <utility> // for s...
You can use an initializer to set default property values:
struct Example {
var upvotes: Int
init() {
upvotes = 42
}
}
let myExample = Example() // call the initializer
print(myExample.upvotes) // prints: 42
Or, specify default property values as a part of the property...
First of all, we need to add our first Fragment at the beginning, we should do it in the onCreate() method of our Activity:
if (null == savedInstanceState) {
getSupportFragmentManager().beginTransaction()
.addToBackStack("fragmentA")
.replace(R.id.container, FragmentA.n...
So let's suppose you want to iterate only between some specific lines of a file
You can make use of itertools for that
import itertools
with open('myfile.txt', 'r') as f:
for line in itertools.islice(f, 12, 30):
# do something here
This will read through the lines 13 to 20 as i...
Swift
textField.textAlignment = .Center
Objective-C
[textField setTextAlignment: NSTextAlignmentCenter];
In the example, we have set the NSTextAlignment to center. You can also set to .Left, .Right, .Justified and .Natural.
.Natural is the default alignment for the current localization. Th...
Flask has a utility called jsonify() that makes it more convenient to return JSON responses
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/api/get-json')
def hello():
return jsonify(hello='world') # Returns HTTP Response with {"hello": "world"}
...
Controllers have access to HTTP parameters (you might know them as ?name=foo in URLs, but Ruby on Rails handle different formats too!) and output different responses based on them. There isn't a way to distinguish between GET and POST parameters, but you shouldn't do that in any case.
class UsersCo...
class UsersController < ApplicationController
def index
respond_to do |format|
format.html do
render html: "Hello #{ user_params[:name] } user_params[:sentence]"
end
end
end
private
def user_params
if params[:name] == "john&quo...
This function runs an AJAX call using GET allowing us to send parameters (object) to a file (string) and launch a callback (function) when the request has been ended.
function ajax(file, params, callback) {
var url = file + '?';
// loop through object and assemble the url
var notFirst ...
Generally, sets are a type of collection which stores unique values. Uniqueness is determined by the equals() and hashCode() methods.
Sorting is determined by the type of set.
HashSet - Random Sorting
Java SE 7
Set<String> set = new HashSet<> ();
set.add("Banana");
set.ad...
The jQuery API may be extended by adding to its prototype. For example, the existing API already has many functions available such as .hide(), .fadeIn(), .hasClass(), etc.
The jQuery prototype is exposed through $.fn, the source code contains the line
jQuery.fn = jQuery.prototype
Adding functio...