This post describes the very basic actions needed to setup a code first approach with Entity Framework (EF) and MySQL Database. For the sake of simplicity a console app is used. The purpose of this post is not to explain Entity Framework or Code First, it is just a getting started guide.
Open Visual Studio and create a new console application:
In Visual Studio, go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution…
Select “browse” and enter “Entity Framework MySQL” in the search box.
Select “MySQL.Data.Entityframework”
At the right side, check “Project” and click install.
Next, open the App.config file. Add a section directly below the <startup> section:
<connectionStrings> <add name="DefaultConnection" providerName="MySql.Data.MySqlClient" connectionString="server=[your mySql server address];User Id=[db user]; Persist Security Info=True;database=[database name];password=[your password]" /> </connectionStrings>
In the entityFramework section delete all providers that do not have invariantname=”MySql.Data.MySqlClient”. There should be only one provider.
Your App.config file should resemble this (with your own server, db,name and credentials):
Next, you will need to write a table class and the DBContext class. To keep things simple we will place this class in program.cs.
Open program.cs, add references to system.Data.Entity and MySQL.Data.EntityFramework. On top of the code:
using System.Data.Entity; using MySql.Data.EntityFramework;
Now add an Author Class , directly under the opening { of the namespace:
public class Author { public int Id { get; set; } public string Name { get; set; } }
This simple class will represent the Authors table in the database. As this is a code first approach, this table does not yet exist!
Following thing to do is to add a DBContext class. Write this directly below the Author class:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class MyDbContext : DbContext
{
public DbSet<Author> Authors { get; set; }
// Constructor - set name of connection
public MyDbContext() : base("name=DefaultConnection")
{
}
}
Three things to note here:
The attribute DbConfigurationType. Needed by Entity Framework to know it is a MySQL Database to talk to
The public DBSet. This tells Entity Framework there will be a table called Authors, of which the model is the class Author.
The (empty) constructor, needed to point to the right connection in App.config.
Next, open the Package Manager Console (Tools>NuGet Package Manager>Package Manager Console)
You will need to tell your project that you will use migrations. This is a one time action. In the Package Manager Console, type: enable-migrations.
If everything is ok, you will get the following message:
If you get errors, check the connection string.
Last step is to generate the Authors table in the database. To do this, first make a migration, after that update the database.
Again, in the package Manager Console, type add-migration [name for the migration]:
The result:
Finally, update the database:
Result:
Done! We have used the Code First approach in Entity Framework to generate a table in a MySQL database.
When developing games for mobile devices the first challenge you will encounter is the difference in screen resolutions. You will want to use the full screen on your device, while maintaining correct aspect ratios.
There are many ways to solve this, in this blog post I will present a simple one. One that works for games that do not use views. One that does not go into depth on camera views etc.
First let’s look at what happens when you set your game to Full Screen.
Gamemaker will size the width and height of your room to match the width and height of your device.
If, for example, your device has a resolution of 1440×900 (like the Samsung Galaxy Tab A 2016), Gamemaker will stretch/shrink the width and height of your room to match this. When you want to get the screen width and height in Gamemaker, it will return the device width and height: 1440×900. This will always be the case, no matter what size your room is, and no matter how you try to retrieve is. So:
display_get_gui_width() will return 1440 display_get_gui_height() will return 900
And also:
display_get_width() will return 1440 display_get_height() will return 900
When designing your game, you will have to choose a resolution to work with. E.g. 900 x 600. To do so, make your room dimensions 900 x 600.
Now what happens? The width of the device is divided into 900 pixels, the height of the device is divided into 600 pixels. Even when your device has a completely different resolution. With our example of a device with a resolution of 1440 x 900 that means:
The width of 900 in GameMaker = 1440 in reality. So one (1) pixel in gamemaker = 1.6 pixels on your device horizontally.
The height of 600 in GameMaker = 900 in reality, so one pixel in gamemaker = 1.5 pixels on your device vertically.
If you have a sprite of a perfect square of 100×100, that square will look perfect on a device with the same (900×600) resolution. In our example device it will have the following dimensions:
width: 100×1.6 = 160 height: 100×1.5 = 150
So the prefect square wil be 160 x 150 on your device: it is no longer a perfect square, it is a rectangle.
a square will be resized to a rectangle
How to solve this?
In your code you must apply a correction factor. To find that factor, you need to know the difference between the horizontal and vertical ratios.
In our example the horizontal ratio is 1.6, the vertical is 1.5.
You will want to multiply the height of your objects in such way that the 1.5 becomes 1.6.
Square This! is both relaxing as well as challenging. There is no time pressure. You can sit back, relax, and solve the puzzles. The game has many levels. Solving a puzzle unlocks a new one. The goal is to swap tiles in a logical order. To unlock a new level the puzzle needs to be solved in a maximum number of turns. Enjoy tapping tiles, enjoy solving the puzzles, enjoy playing this game!
“Square This!” is now available on Google Play.
Google Play and the Google Play logo are trademarks of Google LLC.
With this workout timer app you can make a serie/sequence of timers that are executed one after the other. Every timer has its own time and its own alarm sound. You can make unlimited sequences, and every sequence can have an unlimited amount of timers. This app is ideal for workouts, but can also be used for other things. E.g. Yoga, Reiki, and also as a timer for homework / study, coaching sessions, and many many more.
Google Play and the Google Play logo are trademarks of Google LLC.
Context _ctx = this; AlertDialog.Builder mBuilder = new AlertDialog.Builder(_ctx); mBuilder.setMessage("[The message you want to show]"); mBuilder.setCancelable(false); mBuilder.setPositiveButton("[Button caption for Yes]", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); // Do what is needed if user selects Yes } }); mBuilder.setNegativeButton("Button Title for No]", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); // users selected No } });
#!/usr/bin/perl
# PERL5 CODE SNIPPET
# Get the full HTML of an url and strip all urls in it
use strict;
use warnings;
use LWP::Simple;
# The array that will hold all found urls
my @urls = ();
# the url to scan
my $url = 'http://www.devjockeys.com';
# get the content
my $content = get $url;
die "Couldn't get $url" unless defined $content;
#convert to lowercase
$content = lc($content);
# replace all " to '
$content =~ s/\"/\'/ig;
# search for "a href" tags and strip the urls.
while (index($content, "<a href") != -1) {
my $i = index($content, "<a href");
my $tmp = substr($content, $i );
$content = substr($content, $i + 1 );
my $t = index($tmp,">");
if (index(substr($tmp,0, $t+1),"http") != -1){
my $tmp2 = substr($tmp,0, $t+1);
my $c1 = index($tmp2,"\'");
$tmp2 = substr($tmp2,$c1+1);
$c1 = index($tmp2,"\'");
$tmp2 = substr($tmp2,0,$c1);
# add the url to the array
push @urls, $tmp2;
}
}
# do what ever you like with the found url's. E.g. print them to your console.
foreach(@urls){
print "$_\n";
}
using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
CallWithAsync();
Console.WriteLine("Press any key to quit.");
Console.ReadKey();
}
// common method
private static string GetData(string actionName)
{
// Do your heavy work here. E.g. fetch data from a database.
Thread.Sleep(3000);
return string.Format("Action {0} finished. The time is {1}.", actionName, DateTime.Now.TimeOfDay);
}
// WRAPPER for async methods: these will make "GetData" asynchronous.
private static Task<string> GetDataAsync(string name){
// wrap the GetData method in a Task:
return Task.Run<string>(() =>
{
return GetData(name);
});
}
private async static void CallWithAsync()
{
// Call the async method and wait for its result
string result = await GetDataAsync("Custom Action Name");
Console.WriteLine(result);
}
}
}
Another App updated to the newest iOS version!
Project Time Log has been rebuilt in Swift, with updated API’s for DropBox and SQLite. After five years (first version in 2012!) still up and running!
The goal of Project Time Log is to keep track of time you’ve spent on projects. There are three main actions:
1. Add one or more projects;
2. Start the timer for the project you start working on. Stop the timer when you stop working. You can repeat this as often as you wish;
3. View the log to learn how much time you’ve spent on your projects (per timer, per day and in total).
In addition to these actions you can:
– change project properties any time;
– make changes to your logs or add/delete logs manually: this comes in handy when you forgot to stop or start the timer;
– use the build-in notification system to alert you when a certain amount of time has been exceeded.
– export your logs for use in an external spreadsheet.
– backup and restore your data.
Project Time Log has been designed to be intuitively simple. The best way to get to know it is by testing and trying. There is a predefined ‘test project’ which you can use for that purpose. When finished testing you can delete it without any consequences.
A powerful feature of Project Time Log is that once you’ve started a timer, it will simply keep on counting until you stop it, even when your device is completely switched off.
Best solution for using SQLite in your Swift project is SQLite Swift. It works perfect and comes with very good documentation.
A problem I was facing was converting a field value to an integer.
In short, this was the problematic code:
let db = try Connection(databasePath)
let stmt = try db.prepare("SELECT someId, someCount, someName FROM someTable")
for row in stmt {
print("row[1] = \(String(describing: row[1]))")
// ... I need row[1] as Integer!
}
I needed to convert row[1] to an Integer.
I tried many solution, found on multiple forums, none of them really worked.
Finally I came up with this:
let db = try Connection(databasePath)
let stmt = try db.prepare("SELECT someId, someCount, someName FROM someTable")
for row in stmt {
let optionalCount : Int64 = Optional(row[1]) as! Int64
let lCount = Int(optionalCount)
// Now I have an integer!
}
The fastest way of coding is doing a lot of copy-paste. I know, you shouldn’t. But most of us do … so lets be honest about that 🙂
Following some copy-paste-ready Swift code for sending e-mails form your iOS app.
// MailerViewController.swift
import UIKit
import MessageUI
class MailerViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let mSubject = "The subject of the e-mail"
let mBody = "Hi! This is an e-mail. Please se the attached file."
let mRecipients = ["info@devjockeys.com", "martin@devjockeys.com", "some_recipient@some_email.com"]
let mAttachment = "Some content".data(using: String.Encoding.utf8, allowLossyConversion: false)!
let mAttachmentName = "attachment_filename.txt"
doEmail(subject: mSubject, body: mBody, recipients: mRecipients, attachment: mAttachment, attachmentName: mAttachmentName)
}
func doEmail(subject: String, body: String, recipients: Array, attachment: Data, attachmentName: String ) {
if MFMailComposeViewController.canSendMail() {
let mailer = MFMailComposeViewController()
mailer.mailComposeDelegate = self
// the subject
mailer.setSubject(subject)
// the recepients: an Array of Strings
mailer.setToRecipients(recipients)
// make an attachment. You can attach anything, as long as it is a "Data?" object
mailer.addAttachmentData(attachment, mimeType: "application/octet-stream", fileName: attachmentName)
// the message body
mailer.setMessageBody(body, isHTML: false)
// present the mailer
self.present(mailer, animated: true, completion: nil)
}
else
{
let alert = UIAlertController(title: "Mail Error", message: "Your device has not been configured to send e-mails", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(okAction)
self.present(alert,animated: true,completion: nil)
}
}
// mailer delegate
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
var message = ""
switch (result)
{
case .cancelled: message = "You cancelled the operation and no e-mail message was sent."
case .saved: message = "You saved the e-mail message in the drafts folder."
case .sent: message = "Mail send: e-mail message sent successfully."
case .failed: message = "Mail failed: the e-mail message was not sent. Please check your e-mail settings."
}
let alert = UIAlertController(title: "Mailer", message: message, preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(okAction)
self.present(alert,animated: true,completion: nil)
// Remove the mail view
self.dismiss(animated: true, completion: nil)
}
}
This code sample demonstrates how you can reorder an array.
A possible scenario is when you have multiple-choise questions that you want to present in a different order every time they are shown.
var arrUniqueNumbers = [1,2,3,4]
print("Array before shuffle: \(arrUniqueNumbers)")
let count = arrUniqueNumbers.count
for i in 0..<count{
let n = Int(arc4random_uniform(UInt32(count-i)))+i
(arrUniqueNumbers[i], arrUniqueNumbers[n]) =
(arrUniqueNumbers[n], arrUniqueNumbers[i])
}
print("Array after shuffle: \(arrUniqueNumbers)")
Learn to recognize intervals, train your ears. With this solfege – ear training app you have the tool to train your musical hearing. With four different levels this app has been developed for everyone that wants to train intervals: from beginners to professional musicians.
Solfege Intervals
Solfege Intervals
Solfege Intervals
Google Play and the Google Play logo are trademarks of Google LLC.
Reading data from a database using a DataReader is fast and easy. If something goes wrong, mostly that has to do with null values.
To prevent that, you can extend the DataReader class with some handy methods.
The example below uses the MySqlClient, however, you can use the same methods for SQL and OleDb.
Also, the example only shows methods for integers and strings. Of course you can write similar methods for all data types.
using System;
namespace Utilities
{
public static class Extentions
{
public static int SafeGetInteger(this MySql.Data.MySqlClient.MySqlDataReader reader, string colName)
{
int result = 0;
if (reader[colName]!= null)
{
string tmp = reader[colName].ToString();
if (int.TryParse(tmp, out result))
{
return result;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
public static string SafeGetString(this MySql.Data.MySqlClient.MySqlDataReader reader, string colName)
{
if (reader[colName] != null)
return reader[colName].ToString();
else
return string.Empty;
}
}
}
Everybody experiences moodswings in some way or another, it is a natural thing. There can be a lot of reasons for wanting to get an insight in your moodswings, from simply being interested to being diagnosed bipolar.
DevJockeys developed the iOS app ‘How was your mood’. It is a friendly app, which helps you to document your mood swings on a daily basis, by asking you a simple question: how was your mood today? Because it is so important to know if your mood change was a reaction to events, or seemed to have no reason at all, the app enables you to make notes, which you can easily access in the graph. Intuitive and simple!
INSTRUCTIONS
*start screen:
pan or tap to set your daily mood
select “date” to fill in moods for other (past) dates
after setting your mood, select “note” to make some notes for this day
tap on “overview” to show the graph
tap on “settings” to open the settings view
*settings
enable or disable autocorrection while editing notes
enable or disable daily notifications. When switched on, tap the “edit” button to set a notification time. The app will remind you to fill in your mood at the time you set here daily