This is a quick guide to Kotlin programming language. The previous part of this guide is here
#Object Oriented
fun main(args : Array<String>) {
class local (val x : Int)
val y = local(10)
println("${y.x}")
This is a quick guide to Kotlin programming language. The previous part of this guide is here
#Object Oriented
fun main(args : Array<String>) {
class local (val x : Int)
val y = local(10)
println("${y.x}")
#Intro
Kotlin is a new programming language for the JVM. It produces Java bytecode, supports Android and generates JavaScript. The latest version of the language is Kotlin M5.3
Kotlin project website is at kotlin.jetbrains.org.
All the codes here can be copied and run on Kotlin online editor.
Let's get started.
#Control Structures
##If statement
Kotlin if statement should look familiar with other language
fun main(args : Array<String>) {
val total = 10
<? | |
$ftp_server = "ftp.domainname.com"; | |
$ftp_user_name = "ftp_username"; | |
$ftp_user_pass = "ftp_password"; | |
$ftp_directory = 'path/to/folder/'; // leave blank | |
$ftp_source_file_name = "data.xml"; | |
$ftp_dest_file_name = $ftp_source_file_name; | |
if( ftp_file( $ftp_server, $ftp_user_name, $ftp_user_pass, $ftp_source_file_name, $ftp_directory, $ftp_dest_file_name) ){ | |
echo "Success: FTP'd data\n"; |
from django.http import HttpResponse | |
PIXEL_GIF_DATA = """ | |
R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 | |
""".strip().decode('base64') | |
def pixel_gif(request): | |
return HttpResponse(PIXEL_GIF_DATA, content_type='image/gif') |
Magic words:
psql -U postgres
Some interesting flags (to see all, use -h
or --help
depending on your psql version):
-E
: will describe the underlaying queries of the \
commands (cool for learning!)-l
: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
public class Startup | |
{ | |
public IServiceProvider ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc().AddJsonOptions(options => | |
{ | |
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); | |
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; | |
}); | |
} |
from django.db.models import Count, Max | |
unique_fields = ['field_1', 'field_2'] | |
duplicates = ( | |
MyModel.objects.values(*unique_fields) | |
.order_by() | |
.annotate(max_id=Max('id'), count_id=Count('id')) | |
.filter(count_id__gt=1) | |
) |