├── .ruby-version ├── code ├── ruby │ ├── file_copy.rb │ ├── file_path.rb │ ├── other_time.rb │ ├── array_size.rb │ ├── math_sqrt.rb │ ├── number_random.rb │ ├── other_comment.rb │ ├── type_int_to_float.rb │ ├── type_int_to_string.rb │ ├── array_concat.rb │ ├── array_sort.rb │ ├── array_unique.rb │ ├── conditional_if.rb │ ├── file_get_working_dir.rb │ ├── other_run_command.rb │ ├── type_string_to_int.rb │ ├── array_is_include.rb │ ├── array_reduce.rb │ ├── file_dir_path.rb │ ├── string_split.rb │ ├── type_is_string.rb │ ├── array_with_different_types.rb │ ├── conditional_ternary.rb │ ├── loop_times.rb │ ├── number_increment.rb │ ├── other_date.rb │ ├── string_remove_whistespace.rb │ ├── type_get_type.rb │ ├── loop_until.rb │ ├── other_not.rb │ ├── string_concat.rb │ ├── array_index_of_element.rb │ ├── string_regex.rb │ ├── array_create_populated.rb │ ├── array_find.rb │ ├── array_iterate.rb │ ├── loop_for.rb │ ├── loop_for_with_step.rb │ ├── string_create.rb │ ├── string_replace.rb │ ├── array_count.rb │ ├── array_map.rb │ ├── array_select.rb │ ├── conditional_unless.rb │ ├── loop_while.rb │ ├── math_max_min.rb │ ├── method_declare.rb │ ├── number_compare.rb │ ├── other_destructing_assignment.rb │ ├── other_structure_constant.rb │ ├── array_delete_element.rb │ ├── string_compare.rb │ ├── array_add.rb │ ├── array_multi.rb │ ├── file_parent_dir_path.rb │ ├── other_assign_value_if_not_exist.rb │ ├── string_remove.rb │ ├── array_get_first_and_last.rb │ ├── conditional_and_or.rb │ ├── conditional_if_else.rb │ ├── hash_size.rb │ ├── error_throw.rb │ ├── error_with_a_message.rb │ ├── file_sister_dir_path.rb │ ├── other_structure_boolean.rb │ ├── hash_create_populated.rb │ ├── loop_break.rb │ ├── loop_next.rb │ ├── number_float.rb │ ├── conditional_assign_this_or_that.rb │ ├── file_read.rb │ ├── hash_get_value.rb │ ├── array_iterate_with_index.rb │ ├── conditional_if_assign.rb │ ├── loop_return_array.rb │ ├── string_interpolation.rb │ ├── hash_add.rb │ ├── hash_is_include.rb │ ├── hash_iterate.rb │ ├── other_file_to_import.rb │ ├── class_declare.rb │ ├── class_class_method.rb │ ├── error_method.rb │ ├── file_write.rb │ ├── method_multi_arg.rb │ ├── other_structure_constant_list.rb │ ├── method_default_value.rb │ ├── class_get_set.rb │ ├── method_closure.rb │ ├── method_alias.rb │ ├── class_has_method.rb │ ├── error_try_catch.rb │ ├── other_structure_struct.rb │ ├── class_inheritance.rb │ ├── other_import_file.rb │ ├── class_constructor.rb │ ├── class_field.rb │ ├── class_private_method.rb │ ├── method_return.rb │ ├── class_private_method_access_instance_var.rb │ ├── conditional_switch_as_else_if.rb │ ├── class_method_call.rb │ ├── conditional_switch.rb │ ├── method_block_binding.rb │ ├── class_mixin.rb │ ├── method_init_in_runtime.rb │ ├── other_safe_navigation.rb │ ├── method_block_passing.rb │ └── type_null_true_false.rb ├── python │ ├── file_copy.py │ ├── file_path.py │ ├── array_size.py │ ├── other_comment.py │ ├── type_int_to_float.py │ ├── type_int_to_string.py │ ├── type_string_to_int.py │ ├── array_concat.py │ ├── array_is_include.py │ ├── array_sort.py │ ├── array_unique.py │ ├── string_split.py │ ├── type_is_string.py │ ├── array_iterate.py │ ├── array_with_different_types.py │ ├── conditional_if.py │ ├── loop_times.py │ ├── number_increment.py │ ├── string_concat.py │ ├── string_remove_whistespace.py │ ├── conditional_ternary.py │ ├── math_sqrt.py │ ├── type_get_type.py │ ├── array_index_of_element.py │ ├── file_get_working_dir.py │ ├── loop_for.py │ ├── loop_while.py │ ├── other_date.py │ ├── string_create.py │ ├── array_create_populated.py │ ├── loop_for_with_step.py │ ├── loop_until.py │ ├── method_declare.py │ ├── number_random.py │ ├── other_destructing_assignment.py │ ├── other_not.py │ ├── other_time.py │ ├── string_replace.py │ ├── array_map.py │ ├── conditional_if_assign.py │ ├── math_max_min.py │ ├── number_compare.py │ ├── other_structure_constant.py │ ├── array_count.py │ ├── conditional_unless.py │ ├── file_dir_path.py │ ├── string_compare.py │ ├── array_delete_element.py │ ├── array_find.py │ ├── array_select.py │ ├── conditional_if_else.py │ ├── error_with_a_message.py │ ├── array_add.py │ ├── array_get_first_and_last.py │ ├── array_multi.py │ ├── other_run_command.py │ ├── string_remove.py │ ├── file_parent_dir_path.py │ ├── hash_size.py │ ├── error_throw.py │ ├── file_sister_dir_path.py │ ├── hash_create_populated.py │ ├── other_file_to_import.py │ ├── other_structure_boolean.py │ ├── array_iterate_with_index.py │ ├── conditional_assign_this_or_that.py │ ├── hash_get_value.py │ ├── loop_break.py │ ├── loop_return_array.py │ ├── string_regex.py │ ├── 3.6 │ │ └── string_interpolation.py │ ├── class_declare.py │ ├── conditional_and_or.py │ ├── hash_is_include.py │ ├── loop_next.py │ ├── other_assign_value_if_not_exist.py │ ├── string_interpolation.py │ ├── hash_add.py │ ├── hash_iterate.py │ ├── error_try_catch.py │ ├── file_read.py │ ├── class_class_method.py │ ├── class_get_set.py │ ├── method_alias.py │ ├── other_structure_constant_list.py │ ├── method_default_value.py │ ├── method_multi_arg.py │ ├── error_method.py │ ├── class_has_method.py │ ├── file_write.py │ ├── method_closure.py │ ├── number_float.py │ ├── array_reduce.py │ ├── class_inheritance.py │ ├── conditional_switch_as_else_if.py │ ├── other_import_file.py │ ├── class_constructor.py │ ├── class_field.py │ ├── class_private_method.py │ ├── class_private_method_access_instance_var.py │ ├── other_structure_struct.py │ ├── method_return.py │ ├── class_method_call.py │ ├── method_block_passing.py │ ├── class_mixin.py │ ├── conditional_switch.py │ ├── method_block_binding.py │ ├── method_init_in_runtime.py │ └── type_null_true_false.py ├── file.txt ├── javascript │ ├── class-mixin.js │ ├── method-init-in-runtime.js │ ├── file-path.js │ ├── other-comment.js │ ├── other-time.js │ ├── file-dir-path.js │ ├── math-sqrt.js │ ├── array-size.js │ ├── array-sort.js │ ├── array-concat.js │ ├── array-is-include.js │ ├── conditional-if.js │ ├── file-get-working-dir.js │ ├── type-int-to-float.js │ ├── type-int-to-string.js │ ├── type-string-to-int.js │ ├── array-iterate.js │ ├── array-with-different-types.js │ ├── conditional-ternary.js │ ├── string-concat.js │ ├── string-remove-whistespace.js │ ├── string-split.js │ ├── type-is-string.js │ ├── array-reduce.js │ ├── number-increment.js │ ├── array-index-of-element.js │ ├── loop-for.js │ ├── loop-until.js │ ├── other-not.js │ ├── loop-times.js │ ├── loop-while.js │ ├── string-create.js │ ├── string-replace.js │ ├── array-create-populated.js │ ├── array-map.js │ ├── conditional-unless.js │ ├── loop-for-with-step.js │ ├── other-structure-constant.js │ ├── array-find.js │ ├── method-declare.js │ ├── other-destructing-assignment.js │ ├── string-regex.js │ ├── array-count.js │ ├── array-select.js │ ├── string-compare.js │ ├── string-remove.js │ ├── array-add.js │ ├── file-parent-dir-path.js │ ├── number-compare.js │ ├── array-multi.js │ ├── conditional-and-or.js │ ├── other-structure-boolean.js │ ├── conditional-if-else.js │ ├── error-with-a-message.js │ ├── file-sister-dir-path.js │ ├── hash-create-populated.js │ ├── error-throw.js │ ├── hash-get-value.js │ ├── loop-break.js │ ├── loop-next.js │ ├── array-iterate-with-index.js │ ├── hash-is-include.js │ ├── hash-size.js │ ├── loop-return-array.js │ ├── number-random.js │ ├── hash-add.js │ ├── string-interpolation.js │ ├── array-delete-element.js │ ├── class-declare.js │ ├── math-max-min.js │ ├── class-class-method.js │ ├── other-run-command.js │ ├── number-float.js │ ├── other-file-to-import.js │ ├── other-structure-constant-list.js │ ├── type-get-type.js │ ├── method-default-value.js │ ├── method-multi-arg.js │ ├── array-unique.js │ ├── hash-iterate.js │ ├── array-get-first-and-last.js │ ├── class-has-method.js │ ├── error-try-catch.js │ ├── method-closure.js │ ├── file-write.js │ ├── file-read.js │ ├── class-method-call.js │ ├── method-alias.js │ ├── class-inheritance.js │ ├── class-constructor.js │ ├── method-block-passing.js │ ├── other-date.js │ ├── class-get-set.js │ ├── class-field.js │ ├── conditional-switch.js │ ├── other-import-file.js │ ├── method-return.js │ └── method-block-binding.js ├── kotlin │ ├── MathSqrt.kts │ ├── NumberRandom.kts │ ├── OtherComment.kts │ ├── TypeIntToFloat.kts │ ├── TypeIntToString.kts │ ├── TypeIsString.kts │ ├── TypeStringToInt.kts │ ├── ArraySize.kts │ ├── ConditionalIf.kts │ ├── ArrayConcat.kts │ ├── ArrayIsInclude.kts │ ├── ArraySort.kts │ ├── LoopTimes.kts │ ├── OtherTime.kts │ ├── StringRemoveWhitespace.kts │ ├── StringSplit.kts │ ├── ArrayUnique.kts │ ├── ArrayWithDifferentTypes.kts │ ├── NumberIncrement.kts │ ├── ConditionalTernary.kts │ ├── StringConcat.kts │ ├── TypeGetType.kts │ ├── ArrayIndexOfElement.kts │ ├── LoopFor.kts │ ├── LoopForWithStep.kts │ ├── OtherNot.kts │ ├── OtherDate.kts │ ├── StringCreate.kts │ ├── StringReplace.kts │ ├── ArrayCreatePopulated.kts │ ├── ArrayIterate.kts │ ├── ArrayMap.kts │ ├── ConditionalUnless.kts │ ├── LoopWhile.kts │ ├── MethodDeclare.kts │ ├── OtherAssignValueIfNotExist.kts │ ├── OtherStructureConstant.kts │ ├── ArrayCount.kts │ ├── ArrayFind.kts │ ├── ArrayReduce.kts │ ├── ConditionalIfAssign.kts │ ├── LoopUntil.kts │ ├── NumberCompare.kts │ ├── StringCompare.kts │ ├── ArraySelect.kts │ ├── ConditionalAndOr.kts │ ├── OtherStructureBoolean.kts │ ├── StringRemove.kts │ ├── ConditionalIfElse.kts │ ├── OtherDestructingAssignment.kts │ ├── ArrayDeleteElement.kts │ ├── MathMaxMin.kts │ ├── StringRegex.kts │ ├── ArrayAdd.kts │ ├── ArrayGetFirstAndLast.kts │ ├── HashSize.kts │ ├── ArrayMulti.kts │ ├── ErrorWithAMessage.kts │ ├── LoopBreak.kts │ ├── LoopNext.kts │ ├── LoopReturnArray.kts │ ├── StringInterpolation.kts │ ├── ClassGetSet.kts │ ├── ConditionalAssignThisOrThat.kts │ ├── ErrorThrow.kts │ ├── HashCreatePopulated.kts │ ├── HashGetValue.kts │ ├── ArrayIterateWithIndex.kts │ ├── ClassClassMethod.kts │ ├── ClassDeclare.kts │ ├── HashIsInclude.kts │ ├── NumberFloat.kts │ ├── HashAdd.kts │ ├── HashIterate.kts │ ├── OtherStructureConstantList.kts │ ├── MethodDefaultValue.kts │ ├── MethodClosure.kts │ ├── ErrorTryCatch.kts │ ├── MethodMultiArg.kts │ ├── ErrorMethod.kts │ ├── ClassConstructor.kts │ ├── MethodAlias.kts │ ├── OtherStructureStruct.kts │ ├── ClassHasMethod.kts │ ├── FileRead.kts │ ├── ConditionalSwitchAsElseIf.kts │ ├── ClassPrivateMethod.kts │ ├── ClassInheritance.kts │ ├── ClassPrivateMethodAccessInstance.kts │ ├── ConditionalSwitch.kts │ ├── ClassField.kts │ ├── OtherSafeNavigation.kts │ ├── ClassMethodCall.kts │ ├── MethodReturn.kts │ ├── MethodBlockPassing.kts │ ├── ClassMixin.kts │ └── MethodBlockBinding.kts ├── php │ ├── FileDirPath.php │ ├── FilePath.php │ ├── MathSqrt.php │ ├── NumberRandom.php │ ├── OtherComment.php │ ├── FileGetWorkingDir.php │ ├── TypeIntToFloat.php │ ├── TypeStringToInt.php │ ├── OtherFileToImport.php │ ├── StringRemoveWhitespace.php │ ├── TypeIntToString.php │ ├── ArrayDifferentTypes.php │ ├── ArrayIsInclude.php │ ├── ConditionalIf.php │ ├── NumberIncrement.php │ ├── ArraySize.php │ ├── FileParentDirPath.php │ ├── OtherDate.php │ ├── StringCompare.php │ ├── StringConcat.php │ ├── OtherTime.php │ ├── ArraySort.php │ ├── ConditionalTernary.php │ ├── FileSisterDirPath.php │ ├── LoopTimes.php │ ├── StringCreate.php │ ├── ArrayCreatePopulated.php │ ├── ArrayIterate.php │ ├── LoopFor.php │ ├── LoopUntil.php │ ├── LoopWhile.php │ ├── OtherNot.php │ ├── LoopForWithStep.php │ ├── ConditionalUnless.php │ ├── FileWrite.php │ ├── OtherStructureConstant.php │ ├── ArrayIndexOfElement.php │ ├── ArrayMulti.php │ ├── ConditionalIfElse.php │ ├── MathMaxMin.php │ ├── OtherRunCommand.php │ ├── ArrayUnique.php │ ├── MethodDeclare.php │ ├── NumberCompare.php │ ├── StringSplit.php │ ├── ArrayAdd.php │ ├── FileRead.php │ ├── HashSize.php │ ├── TypeIsString.php │ ├── HashCreatePopulated.php │ ├── OtherStructureBoolean.php │ ├── ArrayGetFirstAndLast.php │ ├── ConditionalAndOr.php │ ├── HashGetValue.php │ ├── string_interpolation.php │ ├── StringRegex.php │ ├── StringReplace.php │ ├── NumberFloat.php │ ├── ArrayConcat.php │ ├── HashAdd.php │ ├── HashIsInclude.php │ ├── ArrayDeleteElement.php │ ├── LoopBreak.php │ ├── LoopNext.php │ ├── ArrayMap.php │ ├── ErrorThrow.php │ ├── OtherImportFile.php │ ├── StringRemove.php │ ├── TypeGetType.php │ ├── ErrorWithAMessage.php │ ├── ArrayCount.php │ ├── ArraySelect.php │ ├── ArrayReduce.php │ ├── HashIterate.php │ ├── ArrayIterateWithIndex.php │ ├── ClassClassMethod.php │ ├── MethodMultiArg.php │ ├── ErrorTryCatch.php │ ├── ClassDeclare.php │ ├── ArrayFind.php │ ├── TypeNullTrueFalse.php │ ├── ConditionalSwitch.php │ ├── ClassHasMethod.php │ ├── MethodReturn.php │ ├── ClassInheritance.php │ ├── ClassPrivateMethod.php │ ├── ClassConstructor.php │ ├── ClassField.php │ ├── ClassGetSet.php │ ├── ClassPrivateMethodAccessInstance.php │ └── ClassMethodCall.php └── java │ ├── OtherComment.java │ ├── MathSqrt.java │ ├── OtherFileToImport.java │ ├── TypeIntToFloat.java │ ├── TypeIsString.java │ ├── ConditionalIf.java │ ├── StringConcat.java │ ├── TypeIntToString.java │ ├── TypeStringToInt.java │ ├── StringRemoveWhitespace.java │ ├── FileGetWorkingDir.java │ ├── LoopFor.java │ ├── LoopTimes.java │ ├── NumberIncrement.java │ ├── LoopForWithStep.java │ ├── StringCreate.java │ ├── ConditionalTernary.java │ ├── LoopUntil.java │ ├── LoopWhile.java │ ├── OtherNot.java │ ├── ArrayIsInclude.java │ ├── ArrayDifferentTypes.java │ ├── StringReplace.java │ ├── TypeGetType.java │ ├── ConditionalUnless.java │ ├── OtherStructureConstant.java │ ├── ArraySize.java │ ├── StringCompare.java │ ├── StringRemove.java │ ├── ConditionalIfElse.java │ ├── NumberCompare.java │ ├── OtherStructureBoolean.java │ ├── ArrayIterate.java │ ├── MethodDeclare.java │ ├── ConditionalAndOr.java │ ├── NumberRandom.java │ ├── ArrayCreatePopulated.java │ ├── LoopBreak.java │ ├── LoopNext.java │ ├── ArrayIndexOfElement.java │ ├── ClassDeclare.java │ ├── ErrorWithAMessage.java │ ├── ArraySort.java │ ├── ErrorThrow.java │ ├── ArrayReduce.java │ ├── ClassClassMethod.java │ ├── StringSplit.java │ ├── ArrayAdd.java │ ├── FileDirPath.java │ ├── NumberFloat.java │ ├── OtherTime.java │ ├── FilePath.java │ ├── ArrayUnique.java │ ├── StringRegex.java │ ├── MathMaxMin.java │ ├── OtherDate.java │ ├── ArrayGetFirstAndLast.java │ ├── ErrorTryCatch.java │ ├── ArrayCount.java │ ├── HashAdd.java │ ├── OtherImportFile.java │ ├── HashSize.java │ ├── ArrayMap.java │ ├── ArrayIterateWithIndex.java │ ├── ArrayMulti.java │ ├── HashCreatePopulated.java │ ├── HashGetValue.java │ ├── ArraySelect.java │ ├── HashIsInclude.java │ ├── MethodMultiArg.java │ ├── MethodReturn.java │ ├── ArrayConcat.java │ ├── ArrayFind.java │ ├── ClassInheritance.java │ ├── ConditionalSwitch.java │ ├── FileParentDirPath.java │ ├── ClassPrivateMethod.java │ ├── ClassConstructor.java │ ├── FileWrite.java │ ├── FileSisterDirPath.java │ ├── ArrayDeleteElement.java │ ├── TypeNullTrueFalse.java │ ├── ClassField.java │ ├── ClassPrivateMethodAccessInstance.java │ ├── ClassGetSet.java │ ├── OtherStructureConstantList.java │ ├── ClassMethodCall.java │ ├── HashIterate.java │ ├── ClassHasMethod.java │ ├── OtherRunCommand.java │ └── FileRead.java ├── source ├── stylesheets │ ├── syntax.css.erb │ └── all.css.scss ├── javascripts │ ├── all.js │ └── main.js ├── _content.haml ├── layouts │ └── layout.haml └── template.haml ├── .gitignore ├── .rubocop.yml ├── Gemfile ├── config.rb ├── LICENSE ├── helpers └── custom_helpers.rb ├── Rakefile ├── README.md ├── Gemfile.lock └── data └── code.yml /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.3.7 2 | -------------------------------------------------------------------------------- /code/ruby/file_copy.rb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /code/python/file_copy.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /code/file.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | World 3 | -------------------------------------------------------------------------------- /code/javascript/class-mixin.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /code/javascript/method-init-in-runtime.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /code/ruby/file_path.rb: -------------------------------------------------------------------------------- 1 | puts __FILE__ 2 | -------------------------------------------------------------------------------- /code/ruby/other_time.rb: -------------------------------------------------------------------------------- 1 | puts Time.now 2 | -------------------------------------------------------------------------------- /code/kotlin/MathSqrt.kts: -------------------------------------------------------------------------------- 1 | println(Math.sqrt(9.0)) -------------------------------------------------------------------------------- /code/python/file_path.py: -------------------------------------------------------------------------------- 1 | print(__file__) 2 | -------------------------------------------------------------------------------- /code/ruby/array_size.rb: -------------------------------------------------------------------------------- 1 | puts [1, 2, 3].size 2 | -------------------------------------------------------------------------------- /code/ruby/math_sqrt.rb: -------------------------------------------------------------------------------- 1 | puts Math.sqrt(9) 2 | -------------------------------------------------------------------------------- /code/ruby/number_random.rb: -------------------------------------------------------------------------------- 1 | puts rand(1..2) 2 | -------------------------------------------------------------------------------- /code/ruby/other_comment.rb: -------------------------------------------------------------------------------- 1 | # it's a comment 2 | -------------------------------------------------------------------------------- /code/ruby/type_int_to_float.rb: -------------------------------------------------------------------------------- 1 | puts 10.to_f 2 | -------------------------------------------------------------------------------- /code/ruby/type_int_to_string.rb: -------------------------------------------------------------------------------- 1 | puts 10.to_s 2 | -------------------------------------------------------------------------------- /code/kotlin/NumberRandom.kts: -------------------------------------------------------------------------------- 1 | println((1..2).random()) -------------------------------------------------------------------------------- /code/kotlin/OtherComment.kts: -------------------------------------------------------------------------------- 1 | // it's a comment 2 | -------------------------------------------------------------------------------- /code/kotlin/TypeIntToFloat.kts: -------------------------------------------------------------------------------- 1 | println(10.toDouble()) -------------------------------------------------------------------------------- /code/kotlin/TypeIntToString.kts: -------------------------------------------------------------------------------- 1 | println(10.toString()) -------------------------------------------------------------------------------- /code/kotlin/TypeIsString.kts: -------------------------------------------------------------------------------- 1 | println("10" is String) -------------------------------------------------------------------------------- /code/kotlin/TypeStringToInt.kts: -------------------------------------------------------------------------------- 1 | println("5".toInt()) -------------------------------------------------------------------------------- /code/python/array_size.py: -------------------------------------------------------------------------------- 1 | print(len([1, 2, 3])) 2 | -------------------------------------------------------------------------------- /code/python/other_comment.py: -------------------------------------------------------------------------------- 1 | # it's a comment 2 | -------------------------------------------------------------------------------- /code/python/type_int_to_float.py: -------------------------------------------------------------------------------- 1 | print(float(10)) 2 | -------------------------------------------------------------------------------- /code/python/type_int_to_string.py: -------------------------------------------------------------------------------- 1 | print(str(10)) 2 | -------------------------------------------------------------------------------- /code/python/type_string_to_int.py: -------------------------------------------------------------------------------- 1 | print(int('5')) 2 | -------------------------------------------------------------------------------- /code/ruby/array_concat.rb: -------------------------------------------------------------------------------- 1 | puts [1, 2] + [3, 4] 2 | -------------------------------------------------------------------------------- /code/ruby/array_sort.rb: -------------------------------------------------------------------------------- 1 | puts [4, 2, 3, 1].sort 2 | -------------------------------------------------------------------------------- /code/ruby/array_unique.rb: -------------------------------------------------------------------------------- 1 | puts %w(a b a).uniq 2 | -------------------------------------------------------------------------------- /code/ruby/conditional_if.rb: -------------------------------------------------------------------------------- 1 | puts 'Hello' if true 2 | -------------------------------------------------------------------------------- /code/ruby/file_get_working_dir.rb: -------------------------------------------------------------------------------- 1 | puts Dir.getwd 2 | -------------------------------------------------------------------------------- /code/ruby/other_run_command.rb: -------------------------------------------------------------------------------- 1 | puts `ruby -v` 2 | -------------------------------------------------------------------------------- /code/ruby/type_string_to_int.rb: -------------------------------------------------------------------------------- 1 | puts '5'.to_i 2 | -------------------------------------------------------------------------------- /code/javascript/file-path.js: -------------------------------------------------------------------------------- 1 | console.log(__filename); 2 | -------------------------------------------------------------------------------- /code/javascript/other-comment.js: -------------------------------------------------------------------------------- 1 | // it's a comment 2 | -------------------------------------------------------------------------------- /code/javascript/other-time.js: -------------------------------------------------------------------------------- 1 | console.log(new Date()); 2 | -------------------------------------------------------------------------------- /code/kotlin/ArraySize.kts: -------------------------------------------------------------------------------- 1 | println(listOf(1, 2, 3).size) -------------------------------------------------------------------------------- /code/kotlin/ConditionalIf.kts: -------------------------------------------------------------------------------- 1 | if (true) println("Hello") -------------------------------------------------------------------------------- /code/php/FileDirPath.php: -------------------------------------------------------------------------------- 1 | console.log(num)); 2 | -------------------------------------------------------------------------------- /code/javascript/array-with-different-types.js: -------------------------------------------------------------------------------- 1 | console.log(['first', 1]); 2 | -------------------------------------------------------------------------------- /code/javascript/conditional-ternary.js: -------------------------------------------------------------------------------- 1 | console.log(false ? 'no' : 'yes'); 2 | -------------------------------------------------------------------------------- /code/javascript/string-concat.js: -------------------------------------------------------------------------------- 1 | console.log("Don't worry" + ' be happy'); 2 | -------------------------------------------------------------------------------- /code/javascript/string-remove-whistespace.js: -------------------------------------------------------------------------------- 1 | console.log(' eh? '.trim()); 2 | -------------------------------------------------------------------------------- /code/javascript/string-split.js: -------------------------------------------------------------------------------- 1 | console.log('I like beer'.split(' ')); 2 | -------------------------------------------------------------------------------- /code/javascript/type-is-string.js: -------------------------------------------------------------------------------- 1 | console.log(typeof '10' === 'string'); 2 | -------------------------------------------------------------------------------- /code/kotlin/ArrayIndexOfElement.kts: -------------------------------------------------------------------------------- 1 | println(listOf("a", "b", "c").indexOf("c")) -------------------------------------------------------------------------------- /code/kotlin/LoopFor.kts: -------------------------------------------------------------------------------- 1 | (1..3).forEach { i -> 2 | println("$i. Hi") 3 | } -------------------------------------------------------------------------------- /code/kotlin/LoopForWithStep.kts: -------------------------------------------------------------------------------- 1 | (0..4 step 2).forEach { 2 | println(it) 3 | } -------------------------------------------------------------------------------- /code/kotlin/OtherNot.kts: -------------------------------------------------------------------------------- 1 | val angry = false 2 | if (!angry) println("smile!") -------------------------------------------------------------------------------- /code/php/ArrayDifferentTypes.php: -------------------------------------------------------------------------------- 1 | x + y)); 2 | -------------------------------------------------------------------------------- /code/javascript/number-increment.js: -------------------------------------------------------------------------------- 1 | let i = 9; 2 | i++; 3 | console.log(i); 4 | -------------------------------------------------------------------------------- /code/kotlin/OtherDate.kts: -------------------------------------------------------------------------------- 1 | import java.time.LocalDate 2 | println(LocalDate.now()) -------------------------------------------------------------------------------- /code/kotlin/StringCreate.kts: -------------------------------------------------------------------------------- 1 | val greeting = "Hello World!" 2 | println(greeting) -------------------------------------------------------------------------------- /code/kotlin/StringReplace.kts: -------------------------------------------------------------------------------- 1 | println("You should work".replace("work", "rest")) -------------------------------------------------------------------------------- /code/php/ArraySize.php: -------------------------------------------------------------------------------- 1 | format("Y-m-d"); 4 | -------------------------------------------------------------------------------- /code/php/StringCompare.php: -------------------------------------------------------------------------------- 1 | 10 } 3 | -------------------------------------------------------------------------------- /code/ruby/array_map.rb: -------------------------------------------------------------------------------- 1 | arr = [1, 5, 10, 20] 2 | puts arr.map { |num| num * 2 } 3 | -------------------------------------------------------------------------------- /code/ruby/array_select.rb: -------------------------------------------------------------------------------- 1 | arr = [1, 5, 10, 20] 2 | puts arr.select(&:even?) 3 | -------------------------------------------------------------------------------- /code/ruby/conditional_unless.rb: -------------------------------------------------------------------------------- 1 | angry = false 2 | puts 'smile!' unless angry 3 | -------------------------------------------------------------------------------- /code/ruby/loop_while.rb: -------------------------------------------------------------------------------- 1 | i = 0 2 | while i < 3 3 | i += 1 4 | end 5 | puts i 6 | -------------------------------------------------------------------------------- /code/ruby/math_max_min.rb: -------------------------------------------------------------------------------- 1 | arr = [1, 2, 3] 2 | puts arr.min 3 | puts arr.max 4 | -------------------------------------------------------------------------------- /code/ruby/method_declare.rb: -------------------------------------------------------------------------------- 1 | def hey 2 | puts 'How are you?' 3 | end 4 | hey 5 | -------------------------------------------------------------------------------- /code/ruby/number_compare.rb: -------------------------------------------------------------------------------- 1 | puts 1 < 2 && 2 < 3 2 | puts 5 == 5 3 | puts 5 != 5 4 | -------------------------------------------------------------------------------- /code/ruby/other_destructing_assignment.rb: -------------------------------------------------------------------------------- 1 | one, two = [1, 2] 2 | puts one, two 3 | -------------------------------------------------------------------------------- /code/ruby/other_structure_constant.rb: -------------------------------------------------------------------------------- 1 | COST = 100 2 | COST = 50 3 | puts COST 4 | -------------------------------------------------------------------------------- /code/javascript/array-index-of-element.js: -------------------------------------------------------------------------------- 1 | console.log(['a', 'b', 'c'].indexOf('c')); 2 | -------------------------------------------------------------------------------- /code/kotlin/ArrayCreatePopulated.kts: -------------------------------------------------------------------------------- 1 | val arr = listOf("first", "second") 2 | println(arr) -------------------------------------------------------------------------------- /code/kotlin/ArrayIterate.kts: -------------------------------------------------------------------------------- 1 | listOf(1, 2).forEach { num -> 2 | println(num) 3 | } 4 | -------------------------------------------------------------------------------- /code/kotlin/ArrayMap.kts: -------------------------------------------------------------------------------- 1 | val arr = listOf(1, 5, 10, 20) 2 | println(arr.map { it * 2 }) -------------------------------------------------------------------------------- /code/kotlin/ConditionalUnless.kts: -------------------------------------------------------------------------------- 1 | val angry = false 2 | if (!angry) println("smile!") -------------------------------------------------------------------------------- /code/kotlin/LoopWhile.kts: -------------------------------------------------------------------------------- 1 | var i = 0 2 | while (i < 3) { 3 | i += 1 4 | } 5 | println(i) -------------------------------------------------------------------------------- /code/kotlin/MethodDeclare.kts: -------------------------------------------------------------------------------- 1 | fun hey() { 2 | println("How are you?") 3 | } 4 | hey() -------------------------------------------------------------------------------- /code/kotlin/OtherAssignValueIfNotExist.kts: -------------------------------------------------------------------------------- 1 | val speed: Int? = 0 2 | println(speed ?: 15) -------------------------------------------------------------------------------- /code/kotlin/OtherStructureConstant.kts: -------------------------------------------------------------------------------- 1 | val COST = 100 2 | val COST = 50 3 | println(COST) -------------------------------------------------------------------------------- /code/php/OtherTime.php: -------------------------------------------------------------------------------- 1 | format("m/d/y h:i A"); 4 | -------------------------------------------------------------------------------- /code/python/array_map.py: -------------------------------------------------------------------------------- 1 | arr = [1, 5, 10, 20] 2 | print([num * 2 for num in arr]) 3 | -------------------------------------------------------------------------------- /code/python/conditional_if_assign.py: -------------------------------------------------------------------------------- 1 | result = 'a' if True else 'b' 2 | print(result) 3 | -------------------------------------------------------------------------------- /code/python/math_max_min.py: -------------------------------------------------------------------------------- 1 | arr = [1, 2, 3] 2 | print(min(arr)) 3 | print(max(arr)) 4 | -------------------------------------------------------------------------------- /code/python/number_compare.py: -------------------------------------------------------------------------------- 1 | print(1 < 2 < 3) 2 | print(5 == 5) 3 | print(5 != 5) 4 | -------------------------------------------------------------------------------- /code/python/other_structure_constant.py: -------------------------------------------------------------------------------- 1 | COST = 100 2 | COST = 50 3 | print(COST) 4 | -------------------------------------------------------------------------------- /code/ruby/array_delete_element.rb: -------------------------------------------------------------------------------- 1 | arr = %w(a b c) 2 | arr.delete('b') 3 | puts arr 4 | -------------------------------------------------------------------------------- /code/ruby/string_compare.rb: -------------------------------------------------------------------------------- 1 | puts 'string' == 'string' 2 | puts 'string' != 'string' 3 | -------------------------------------------------------------------------------- /code/javascript/loop-for.js: -------------------------------------------------------------------------------- 1 | for (let i = 1; i < 4; i++) 2 | console.log(`${i}. Hi`); 3 | -------------------------------------------------------------------------------- /code/javascript/loop-until.js: -------------------------------------------------------------------------------- 1 | let i = 0; 2 | while (i !== 3) i += 1; 3 | console.log(i); 4 | -------------------------------------------------------------------------------- /code/javascript/other-not.js: -------------------------------------------------------------------------------- 1 | const angry = false; 2 | if (!angry) console.log('smile!'); 3 | -------------------------------------------------------------------------------- /code/kotlin/ArrayCount.kts: -------------------------------------------------------------------------------- 1 | val arr = listOf(1, 11, 111) 2 | println(arr.count { it > 10 }) -------------------------------------------------------------------------------- /code/kotlin/ArrayFind.kts: -------------------------------------------------------------------------------- 1 | val arr = listOf(1, 5, 10, 20) 2 | println(arr.find { it % 2 == 0 }) -------------------------------------------------------------------------------- /code/kotlin/ArrayReduce.kts: -------------------------------------------------------------------------------- 1 | println(listOf(1, 2, 3).reduce { sum, element -> sum + element }) -------------------------------------------------------------------------------- /code/kotlin/ConditionalIfAssign.kts: -------------------------------------------------------------------------------- 1 | val result = if (true) 'a' else 'b' 2 | println(result) -------------------------------------------------------------------------------- /code/kotlin/LoopUntil.kts: -------------------------------------------------------------------------------- 1 | var i = 0 2 | while (i != 3) { 3 | i += 1 4 | } 5 | println(i) -------------------------------------------------------------------------------- /code/kotlin/NumberCompare.kts: -------------------------------------------------------------------------------- 1 | println(1 < 2 && 2 < 3) 2 | println(5 == 5) 3 | println(5 != 5) -------------------------------------------------------------------------------- /code/kotlin/StringCompare.kts: -------------------------------------------------------------------------------- 1 | println("string" == "string") 2 | println("string" != "string") -------------------------------------------------------------------------------- /code/php/ArraySort.php: -------------------------------------------------------------------------------- 1 | 10)) 3 | -------------------------------------------------------------------------------- /code/python/conditional_unless.py: -------------------------------------------------------------------------------- 1 | angry = False 2 | if not angry: 3 | print('smile!') 4 | -------------------------------------------------------------------------------- /code/python/file_dir_path.py: -------------------------------------------------------------------------------- 1 | import pathlib 2 | 3 | print(pathlib.Path(__file__).parent) 4 | -------------------------------------------------------------------------------- /code/python/string_compare.py: -------------------------------------------------------------------------------- 1 | print('string' == 'string') 2 | print('string' != 'string') 3 | -------------------------------------------------------------------------------- /code/ruby/array_add.rb: -------------------------------------------------------------------------------- 1 | arr = [] 2 | arr.push 'first' 3 | arr.push 'second' 4 | puts arr 5 | -------------------------------------------------------------------------------- /code/ruby/array_multi.rb: -------------------------------------------------------------------------------- 1 | multi = [%w(first second), %w(third forth)] 2 | puts multi[1][1] 3 | -------------------------------------------------------------------------------- /code/ruby/file_parent_dir_path.rb: -------------------------------------------------------------------------------- 1 | puts File.expand_path File.join(__FILE__, '..', '..') 2 | -------------------------------------------------------------------------------- /code/ruby/other_assign_value_if_not_exist.rb: -------------------------------------------------------------------------------- 1 | speed = 0 2 | speed ||= 15 3 | puts speed 4 | -------------------------------------------------------------------------------- /code/ruby/string_remove.rb: -------------------------------------------------------------------------------- 1 | puts 'This is not funny! I am not like him!'.gsub('not ', '') 2 | -------------------------------------------------------------------------------- /code/javascript/loop-times.js: -------------------------------------------------------------------------------- 1 | for (let i of Array(3).keys()) { 2 | console.log('Hi'); 3 | } 4 | -------------------------------------------------------------------------------- /code/javascript/loop-while.js: -------------------------------------------------------------------------------- 1 | let i = 0; 2 | while (i < 3) 3 | i += 1; 4 | console.log(i); 5 | -------------------------------------------------------------------------------- /code/javascript/string-create.js: -------------------------------------------------------------------------------- 1 | const greeting = 'Hello World!'; 2 | console.log(greeting); 3 | -------------------------------------------------------------------------------- /code/javascript/string-replace.js: -------------------------------------------------------------------------------- 1 | console.log('You should work'.replace(/work/g, 'rest')); 2 | -------------------------------------------------------------------------------- /code/kotlin/ArraySelect.kts: -------------------------------------------------------------------------------- 1 | val arr = listOf(1, 5, 10, 20) 2 | println(arr.filter { it % 2 == 0 }) -------------------------------------------------------------------------------- /code/php/ArrayCreatePopulated.php: -------------------------------------------------------------------------------- 1 | '.highlight') %> 2 | -------------------------------------------------------------------------------- /code/javascript/array-create-populated.js: -------------------------------------------------------------------------------- 1 | const arr = ['first', 'second']; 2 | console.log(arr); 3 | -------------------------------------------------------------------------------- /code/javascript/array-map.js: -------------------------------------------------------------------------------- 1 | const arr = [1, 5, 10, 20]; 2 | console.log(arr.map(num => num * 2)); 3 | -------------------------------------------------------------------------------- /code/javascript/conditional-unless.js: -------------------------------------------------------------------------------- 1 | const angry = false; 2 | if (!angry) console.log('smile!'); 3 | -------------------------------------------------------------------------------- /code/javascript/loop-for-with-step.js: -------------------------------------------------------------------------------- 1 | for (let i = 0; i < 6; i += 2) { 2 | console.log(i); 3 | } 4 | -------------------------------------------------------------------------------- /code/javascript/other-structure-constant.js: -------------------------------------------------------------------------------- 1 | const COST = 100; 2 | COST = 50; 3 | console.log(COST); 4 | -------------------------------------------------------------------------------- /code/kotlin/ConditionalAndOr.kts: -------------------------------------------------------------------------------- 1 | if (true && false) println("no") 2 | if (true || false) println("yes") -------------------------------------------------------------------------------- /code/kotlin/OtherStructureBoolean.kts: -------------------------------------------------------------------------------- 1 | val tryIt = true 2 | if (tryIt) println("Garlic gum is not funny") -------------------------------------------------------------------------------- /code/kotlin/StringRemove.kts: -------------------------------------------------------------------------------- 1 | println("This is not funny! I am not like him!".replace("not ", "")) 2 | -------------------------------------------------------------------------------- /code/php/LoopForWithStep.php: -------------------------------------------------------------------------------- 1 | e 4 | puts e.message 5 | end 6 | -------------------------------------------------------------------------------- /code/ruby/error_with_a_message.rb: -------------------------------------------------------------------------------- 1 | begin 2 | 1 / 0 3 | rescue => e 4 | puts e.message 5 | end 6 | -------------------------------------------------------------------------------- /code/ruby/file_sister_dir_path.rb: -------------------------------------------------------------------------------- 1 | puts File.expand_path File.join(__FILE__, '..', '..', 'php') 2 | 3 | -------------------------------------------------------------------------------- /code/ruby/other_structure_boolean.rb: -------------------------------------------------------------------------------- 1 | try_it = true 2 | puts 'Garlic gum is not funny' if try_it 3 | -------------------------------------------------------------------------------- /code/javascript/array-find.js: -------------------------------------------------------------------------------- 1 | const arr = [1, 5, 10, 20]; 2 | console.log(arr.find(i => i % 2 === 0)); 3 | -------------------------------------------------------------------------------- /code/javascript/method-declare.js: -------------------------------------------------------------------------------- 1 | function hey() { 2 | console.log('How are you?'); 3 | } 4 | hey(); 5 | -------------------------------------------------------------------------------- /code/javascript/other-destructing-assignment.js: -------------------------------------------------------------------------------- 1 | const [one, two] = [1, 2]; 2 | console.log(one, two); 3 | -------------------------------------------------------------------------------- /code/javascript/string-regex.js: -------------------------------------------------------------------------------- 1 | console.log('apple'.match(/^b/)); 2 | console.log('apple'.match(/^a/)); 3 | -------------------------------------------------------------------------------- /code/kotlin/ConditionalIfElse.kts: -------------------------------------------------------------------------------- 1 | if (true) { 2 | println("work") 3 | } else { 4 | println("sleep") 5 | } -------------------------------------------------------------------------------- /code/kotlin/OtherDestructingAssignment.kts: -------------------------------------------------------------------------------- 1 | val (one, two) = listOf(1, 2) 2 | println(one) 3 | println(two) -------------------------------------------------------------------------------- /code/php/ConditionalUnless.php: -------------------------------------------------------------------------------- 1 | i > 10).length); 3 | -------------------------------------------------------------------------------- /code/javascript/array-select.js: -------------------------------------------------------------------------------- 1 | const arr = [1, 5, 10, 20]; 2 | console.log(arr.filter(i => i % 2 === 0)); 3 | -------------------------------------------------------------------------------- /code/javascript/string-compare.js: -------------------------------------------------------------------------------- 1 | console.log('string' === 'string'); 2 | console.log('string' !== 'string'); 3 | -------------------------------------------------------------------------------- /code/javascript/string-remove.js: -------------------------------------------------------------------------------- 1 | console.log('This is not funny! I am not like him!'.replace(/not /g, '')); 2 | -------------------------------------------------------------------------------- /code/kotlin/ArrayDeleteElement.kts: -------------------------------------------------------------------------------- 1 | val arr = mutableListOf("a", "b", "c") 2 | arr.remove("b") 3 | println(arr) -------------------------------------------------------------------------------- /code/kotlin/MathMaxMin.kts: -------------------------------------------------------------------------------- 1 | val arr = listOf(1, 2, 3) 2 | println(arr.minOrNull()) 3 | println(arr.maxOrNull()) -------------------------------------------------------------------------------- /code/kotlin/StringRegex.kts: -------------------------------------------------------------------------------- 1 | println("apple".contains(Regex("^b"))) 2 | println("apple".contains(Regex("^a"))) 3 | -------------------------------------------------------------------------------- /code/php/ArrayIndexOfElement.php: -------------------------------------------------------------------------------- 1 | () 2 | arr.add("first") 3 | arr.add("second") 4 | println(arr) -------------------------------------------------------------------------------- /code/kotlin/ArrayGetFirstAndLast.kts: -------------------------------------------------------------------------------- 1 | val arr = listOf("one", "two") 2 | println(arr.first()) 3 | println(arr.last()) -------------------------------------------------------------------------------- /code/kotlin/HashSize.kts: -------------------------------------------------------------------------------- 1 | val options = mapOf("font_size" to 10, "font_family" to "Arial") 2 | println(options.size) -------------------------------------------------------------------------------- /code/php/ArrayUnique.php: -------------------------------------------------------------------------------- 1 | "${i + 1}. Hello!" } 2 | greetings.forEach { println(it) } -------------------------------------------------------------------------------- /code/kotlin/StringInterpolation.kts: -------------------------------------------------------------------------------- 1 | val first = "Don't worry," 2 | val second = "be happy" 3 | println("$first $second") -------------------------------------------------------------------------------- /code/php/ArrayAdd.php: -------------------------------------------------------------------------------- 1 | "10", "fontFamily" => "Arial"]; 4 | echo count($options); -------------------------------------------------------------------------------- /code/php/TypeIsString.php: -------------------------------------------------------------------------------- 1 | "10", "fontFamily" => "Arial"]; 4 | var_dump($options); -------------------------------------------------------------------------------- /code/php/OtherStructureBoolean.php: -------------------------------------------------------------------------------- 1 | "10", "fontFamily" => "Arial"]; 4 | var_dump($options["fontSize"]); -------------------------------------------------------------------------------- /code/php/string_interpolation.php: -------------------------------------------------------------------------------- 1 | e 4 | puts e.message 5 | end 6 | divide(1, 0) 7 | -------------------------------------------------------------------------------- /code/javascript/array-iterate-with-index.js: -------------------------------------------------------------------------------- 1 | ['one', 'two'].forEach((num, i) => { 2 | console.log(num); 3 | console.log(i); 4 | }); 5 | -------------------------------------------------------------------------------- /code/javascript/hash-is-include.js: -------------------------------------------------------------------------------- 1 | const options = { font_size: 10, font_family: 'Arial' }; 2 | console.log('font_size' in options); 3 | -------------------------------------------------------------------------------- /code/javascript/hash-size.js: -------------------------------------------------------------------------------- 1 | const options = { font_size: 10, font_family: 'Arial' }; 2 | console.log(Object.keys(options).length); 3 | -------------------------------------------------------------------------------- /code/javascript/loop-return-array.js: -------------------------------------------------------------------------------- 1 | const greetings = Array(3).fill().map((_, i) => `${i + 1}. Hello!`); 2 | console.log(greetings); 3 | -------------------------------------------------------------------------------- /code/javascript/number-random.js: -------------------------------------------------------------------------------- 1 | const min = 1; 2 | const max = 2; 3 | console.log(Math.floor(Math.random() * (max - min + 1)) + min); 4 | -------------------------------------------------------------------------------- /code/kotlin/ArrayIterateWithIndex.kts: -------------------------------------------------------------------------------- 1 | listOf("one", "two").forEachIndexed { index, num -> 2 | println(num) 3 | println(index) 4 | } -------------------------------------------------------------------------------- /code/kotlin/ClassClassMethod.kts: -------------------------------------------------------------------------------- 1 | object Animal { 2 | fun feed() { 3 | println("Om nom nom") 4 | } 5 | } 6 | 7 | Animal.feed() 8 | -------------------------------------------------------------------------------- /code/kotlin/ClassDeclare.kts: -------------------------------------------------------------------------------- 1 | class Animal { 2 | fun walk() { 3 | println("I'm walking") 4 | } 5 | } 6 | 7 | Animal().walk() 8 | -------------------------------------------------------------------------------- /code/php/StringRegex.php: -------------------------------------------------------------------------------- 1 | e !== 'b')); 3 | console.log(newArr); 4 | -------------------------------------------------------------------------------- /code/javascript/class-declare.js: -------------------------------------------------------------------------------- 1 | class Animal { 2 | walk() { 3 | console.log("I'm walking"); 4 | } 5 | } 6 | 7 | new Animal().walk(); 8 | -------------------------------------------------------------------------------- /code/javascript/math-max-min.js: -------------------------------------------------------------------------------- 1 | const arr = [1, 2, 3]; 2 | console.log(Math.min.apply(this, arr)); 3 | console.log(Math.max.apply(this, arr)); 4 | -------------------------------------------------------------------------------- /code/kotlin/NumberFloat.kts: -------------------------------------------------------------------------------- 1 | println(9 / 2) 2 | println(9 / 2.0) 3 | println(kotlin.math.floor(9 / 2.0)) 4 | println(kotlin.math.round(9 / 2.0)) 5 | -------------------------------------------------------------------------------- /code/php/ArrayConcat.php: -------------------------------------------------------------------------------- 1 | "10", "fontFamily" => "Arial"]; 4 | var_dump(key_exists("fontSize", $options)); -------------------------------------------------------------------------------- /code/python/method_default_value.py: -------------------------------------------------------------------------------- 1 | def send(abroad=False): 2 | print('Send abroad' if abroad else 'Send locally') 3 | send() 4 | send(True) 5 | -------------------------------------------------------------------------------- /code/python/method_multi_arg.py: -------------------------------------------------------------------------------- 1 | def sweets(buy, *brands): 2 | if buy: 3 | print(brands) 4 | sweets(True, 'snickers', 'twix', 'bounty') 5 | -------------------------------------------------------------------------------- /code/ruby/method_default_value.rb: -------------------------------------------------------------------------------- 1 | def send(abroad = false) 2 | puts abroad ? 'Send abroad' : 'Send locally' 3 | end 4 | send 5 | send true 6 | -------------------------------------------------------------------------------- /code/javascript/class-class-method.js: -------------------------------------------------------------------------------- 1 | class Animal { 2 | static feed() { 3 | console.log('Om nom nom'); 4 | } 5 | } 6 | 7 | Animal.feed(); 8 | -------------------------------------------------------------------------------- /code/javascript/other-run-command.js: -------------------------------------------------------------------------------- 1 | const exec = require('child_process').exec; 2 | exec('node -v', (error, stdout, stderr) => console.log(stdout)); 3 | -------------------------------------------------------------------------------- /code/kotlin/HashAdd.kts: -------------------------------------------------------------------------------- 1 | val options = mutableMapOf() 2 | options["font_size"] = 10 3 | options["font_family"] = "Arial" 4 | println(options) -------------------------------------------------------------------------------- /code/kotlin/HashIterate.kts: -------------------------------------------------------------------------------- 1 | mapOf("font_size" to 10, "font_family" to "Arial").forEach { key, value -> 2 | println(key) 3 | println(value) 4 | } 5 | -------------------------------------------------------------------------------- /code/php/ArrayDeleteElement.php: -------------------------------------------------------------------------------- 1 | (x) { x * x } 2 | puts [2, 3].map(&square) 3 | 4 | greeting = -> { puts 'Hello World!' } 5 | greeting.call 6 | -------------------------------------------------------------------------------- /code/java/OtherFileToImport.java: -------------------------------------------------------------------------------- 1 | class OtherFileToImport { 2 | public OtherFileToImport() { 3 | System.out.println("I am imported!"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /code/java/TypeIntToFloat.java: -------------------------------------------------------------------------------- 1 | class TypeIntToFloat { 2 | public static void main(String[] args) { 3 | System.out.println((float) 10); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /code/javascript/number-float.js: -------------------------------------------------------------------------------- 1 | console.log(9 / 2); 2 | console.log(9 / 2.0); 3 | console.log(Math.floor(9 / 2.0)); 4 | console.log(Math.round(9 / 2.0)); 5 | -------------------------------------------------------------------------------- /code/javascript/other-file-to-import.js: -------------------------------------------------------------------------------- 1 | module.exports = 2 | class Import { 3 | constructor() { 4 | console.log('I am imported!'); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/kotlin/OtherStructureConstantList.kts: -------------------------------------------------------------------------------- 1 | object Colors { 2 | const val RED = "#FF0000" 3 | const val GREEN = "#00FF00" 4 | } 5 | println(Colors.GREEN) -------------------------------------------------------------------------------- /code/php/ArrayMap.php: -------------------------------------------------------------------------------- 1 | getMessage(); 7 | } 8 | -------------------------------------------------------------------------------- /code/php/OtherImportFile.php: -------------------------------------------------------------------------------- 1 | getMessage(); 7 | } 8 | -------------------------------------------------------------------------------- /code/python/class_has_method.py: -------------------------------------------------------------------------------- 1 | class Animal: 2 | def walk(self): 3 | print("I'm walking") 4 | 5 | animal = Animal() 6 | print(hasattr(animal, 'walk')) 7 | -------------------------------------------------------------------------------- /code/python/file_write.py: -------------------------------------------------------------------------------- 1 | import pathlib 2 | 3 | with (pathlib.Path(__file__).parent / 'output.txt').open('w') as f: 4 | f.write('Some glorious content') 5 | -------------------------------------------------------------------------------- /code/python/method_closure.py: -------------------------------------------------------------------------------- 1 | square = lambda x: x * x 2 | print(list(map(square, [2, 3]))) 3 | 4 | greeting = lambda: print('Hello World!') 5 | greeting() 6 | -------------------------------------------------------------------------------- /code/python/number_float.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(9 // 2) 4 | print(9 / 2) 5 | print(math.floor(9 / 2)) 6 | print(round(9 / 2)) # rounds half to even 7 | -------------------------------------------------------------------------------- /code/ruby/method_alias.rb: -------------------------------------------------------------------------------- 1 | class Greetings 2 | def hey 3 | puts 'How are you?' 4 | end 5 | alias_method :hi, :hey 6 | end 7 | 8 | Greetings.new.hi 9 | -------------------------------------------------------------------------------- /code/java/TypeIsString.java: -------------------------------------------------------------------------------- 1 | class TypeIsString { 2 | public static void main(String[] args) { 3 | System.out.println("10" instanceof String); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /code/javascript/other-structure-constant-list.js: -------------------------------------------------------------------------------- 1 | const Colors = Object.freeze({ 2 | RED: '#FF0000', 3 | GREEN: '#00FF00' 4 | }); 5 | console.log(Colors.GREEN); 6 | -------------------------------------------------------------------------------- /code/javascript/type-get-type.js: -------------------------------------------------------------------------------- 1 | console.log(typeof 'hi'); 2 | console.log(typeof 1); 3 | console.log('hi'.constructor.name); 4 | console.log((1).constructor.name); 5 | -------------------------------------------------------------------------------- /code/kotlin/MethodClosure.kts: -------------------------------------------------------------------------------- 1 | val square = { x: Int -> x * x } 2 | println(listOf(2, 3).map(square)) 3 | 4 | val greeting = { println("Hello World!") } 5 | greeting() -------------------------------------------------------------------------------- /code/php/ArrayCount.php: -------------------------------------------------------------------------------- 1 | 10) 7 | $count++; 8 | var_dump($count); -------------------------------------------------------------------------------- /code/java/ConditionalIf.java: -------------------------------------------------------------------------------- 1 | class ConditionalIf { 2 | public static void main(String[] args) { 3 | if (true) 4 | System.out.println("Hello"); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/java/StringConcat.java: -------------------------------------------------------------------------------- 1 | class StringConcat { 2 | public static void main(String[] args) { 3 | System.out.println("Don't worry," + " be happy"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /code/java/TypeIntToString.java: -------------------------------------------------------------------------------- 1 | class TypeIntToString { 2 | public static void main(String[] args) { 3 | System.out.println(Integer.toString(10)); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /code/java/TypeStringToInt.java: -------------------------------------------------------------------------------- 1 | class TypeStringToInt { 2 | public static void main(String[] args) { 3 | System.out.println(Integer.parseInt("10")); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /code/javascript/method-default-value.js: -------------------------------------------------------------------------------- 1 | function send(abroad = false) { 2 | console.log(abroad ? 'Send abroad' : 'Send locally'); 3 | } 4 | send(); 5 | send(true); 6 | -------------------------------------------------------------------------------- /code/javascript/method-multi-arg.js: -------------------------------------------------------------------------------- 1 | function sweets(buy, ...brands) { 2 | if (buy) return console.log(brands); 3 | } 4 | sweets(true, 'snickers', 'twix', 'bounty'); 5 | -------------------------------------------------------------------------------- /code/kotlin/ErrorTryCatch.kts: -------------------------------------------------------------------------------- 1 | try { 2 | 1 / 0 3 | } catch (e: ArithmeticException) { 4 | println("Can't divide") 5 | } finally { 6 | println("But that's ok") 7 | } 8 | -------------------------------------------------------------------------------- /code/python/array_reduce.py: -------------------------------------------------------------------------------- 1 | import functools, operator 2 | 3 | print(functools.reduce(operator.add, [1, 2, 3])) 4 | print(sum([1, 2, 3])) # a more Pythonic example 5 | -------------------------------------------------------------------------------- /code/ruby/class_has_method.rb: -------------------------------------------------------------------------------- 1 | class Animal 2 | def walk 3 | puts "I'm walking" 4 | end 5 | end 6 | 7 | animal = Animal.new 8 | puts animal.respond_to? :walk 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle 2 | /build 3 | /.sass-cache 4 | /.cache 5 | .DS_Store 6 | *.class 7 | *.out 8 | output.txt 9 | /middleman.log 10 | tags 11 | *.swp 12 | *.pyc 13 | -------------------------------------------------------------------------------- /code/java/StringRemoveWhitespace.java: -------------------------------------------------------------------------------- 1 | class StringRemoveWhitespace { 2 | public static void main(String[] args) { 3 | System.out.println(" eh? ".trim()); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /code/javascript/array-unique.js: -------------------------------------------------------------------------------- 1 | const arr = ['a', 'b', 'a']; 2 | const unique = arr.filter((value, index, self) => self.indexOf(value) === index); 3 | console.log(unique); 4 | -------------------------------------------------------------------------------- /code/php/ArraySelect.php: -------------------------------------------------------------------------------- 1 | (x * x); 2 | console.log([2, 3].map(num => square(num))); 3 | 4 | const greeting = () => console.log('Hello World!'); 5 | greeting(); 6 | -------------------------------------------------------------------------------- /code/kotlin/ErrorMethod.kts: -------------------------------------------------------------------------------- 1 | fun divide(num1: Int, num2: Int) { 2 | try { 3 | println(num1 / num2) 4 | } catch (e: Exception) { 5 | println(e.message) 6 | } 7 | } 8 | divide(1, 0) -------------------------------------------------------------------------------- /code/php/HashIterate.php: -------------------------------------------------------------------------------- 1 | "10", "fontFamily" => "Arial"]; 4 | foreach ($options as $key => $value) { 5 | echo "$key\n"; 6 | echo "$value\n"; 7 | } -------------------------------------------------------------------------------- /code/java/ConditionalTernary.java: -------------------------------------------------------------------------------- 1 | class ConditionalTernary { 2 | public static void main(String[] args) { 3 | String s = false ? "no" : "yes"; 4 | System.out.println(s); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/java/LoopUntil.java: -------------------------------------------------------------------------------- 1 | class LoopUntil { 2 | public static void main(String[] args) { 3 | int i = 0; 4 | while (i != 3) 5 | i++; 6 | System.out.println(i); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/LoopWhile.java: -------------------------------------------------------------------------------- 1 | class LoopWhile { 2 | public static void main(String[] args) { 3 | int i = 0; 4 | while (i < 3) 5 | i++; 6 | System.out.println(i); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/OtherNot.java: -------------------------------------------------------------------------------- 1 | class OtherNot { 2 | public static void main(String[] args) { 3 | boolean angry = false; 4 | if (!angry) 5 | System.out.println("smile!"); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /code/kotlin/ClassConstructor.kts: -------------------------------------------------------------------------------- 1 | class Animal(private val name: String) { 2 | fun walk() { 3 | println("My name is $name and I'm walking") 4 | } 5 | } 6 | 7 | Animal("Kelya").walk() 8 | -------------------------------------------------------------------------------- /code/kotlin/MethodAlias.kts: -------------------------------------------------------------------------------- 1 | class Greetings { 2 | fun hey() { 3 | println("How are you?") 4 | } 5 | } 6 | 7 | val greetings = Greetings() 8 | greetings.hey().also { greetings::hey } 9 | -------------------------------------------------------------------------------- /code/kotlin/OtherStructureStruct.kts: -------------------------------------------------------------------------------- 1 | data class Customer(val name: String, val address: String) { 2 | fun greeting() = "Hello $name!" 3 | } 4 | println(Customer("Dave", "123 Main").greeting()) 5 | -------------------------------------------------------------------------------- /code/kotlin/ClassHasMethod.kts: -------------------------------------------------------------------------------- 1 | class Animal { 2 | fun walk() { 3 | println("I'm walking") 4 | } 5 | } 6 | 7 | val animal = Animal() 8 | println(animal::class.java.getMethod("walk") != null) 9 | -------------------------------------------------------------------------------- /code/php/ArrayIterateWithIndex.php: -------------------------------------------------------------------------------- 1 | "10", "fontFamily" => "Arial"]; 4 | foreach ($options as $key => $value) { 5 | echo "$key\n"; 6 | echo "$value\n"; 7 | } -------------------------------------------------------------------------------- /code/php/ClassClassMethod.php: -------------------------------------------------------------------------------- 1 | walk(); -------------------------------------------------------------------------------- /code/python/conditional_switch_as_else_if.py: -------------------------------------------------------------------------------- 1 | score = 76 2 | grades = [ 3 | (60, 'F'), 4 | (70, 'D'), 5 | (80, 'C'), 6 | (90, 'B'), 7 | ] 8 | print(next((g for x, g in grades if score < x), 'A')) 9 | -------------------------------------------------------------------------------- /code/python/other_import_file.py: -------------------------------------------------------------------------------- 1 | # other_file_to_import.py 2 | # class Import: 3 | # def __init__(self): 4 | # print('I am imported!') 5 | 6 | import other_file_to_import 7 | other_file_to_import.Import() 8 | -------------------------------------------------------------------------------- /code/kotlin/ConditionalSwitchAsElseIf.kts: -------------------------------------------------------------------------------- 1 | val score = 76 2 | val grade = when { 3 | score < 60 -> 'F' 4 | score < 70 -> 'D' 5 | score < 80 -> 'C' 6 | score < 90 -> 'B' 7 | else -> 'A' 8 | } 9 | println(grade) 10 | -------------------------------------------------------------------------------- /code/php/ArrayFind.php: -------------------------------------------------------------------------------- 1 | arr = Arrays.asList(1, 2, 3); 6 | System.out.println(arr.size()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/StringCompare.java: -------------------------------------------------------------------------------- 1 | class StringCompare { 2 | public static void main(String[] args) { 3 | System.out.println("string".equals("string")); 4 | System.out.println(!"string".equals("string")); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/java/StringRemove.java: -------------------------------------------------------------------------------- 1 | class StringRemove { 2 | public static void main(String[] args) { 3 | String s = "This is not funny! I am not like him!"; 4 | System.out.println(s.replaceAll("not ", "")); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /code/python/class_constructor.py: -------------------------------------------------------------------------------- 1 | class Animal: 2 | def __init__(self, name): 3 | self.name = name 4 | 5 | def walk(self): 6 | print("My name is %s and I'm walking" % self.name) 7 | 8 | Animal('Kelya').walk() 9 | -------------------------------------------------------------------------------- /code/ruby/class_inheritance.rb: -------------------------------------------------------------------------------- 1 | class Animal 2 | def walk 3 | puts "I'm walking" 4 | end 5 | end 6 | 7 | class Dog < Animal 8 | def sing 9 | puts 'Bark!' 10 | end 11 | end 12 | 13 | Dog.new.walk 14 | -------------------------------------------------------------------------------- /code/java/ConditionalIfElse.java: -------------------------------------------------------------------------------- 1 | class ConditionalIfElse { 2 | public static void main(String[] args) { 3 | if (true) 4 | System.out.println("work"); 5 | else 6 | System.out.println("sleep"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/NumberCompare.java: -------------------------------------------------------------------------------- 1 | class NumberCompare { 2 | public static void main(String[] args) { 3 | System.out.println(1 < 2 && 2 < 3); 4 | System.out.println(5 == 5); 5 | System.out.println(5 != 5); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /code/php/TypeNullTrueFalse.php: -------------------------------------------------------------------------------- 1 | arr = Arrays.asList("first", "second"); 6 | System.out.println(arr); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/python/class_field.py: -------------------------------------------------------------------------------- 1 | class Animal: 2 | def take(self, toy): 3 | self.toy = toy 4 | 5 | def play(self): 6 | print("I'm playing with %s" % self.toy) 7 | 8 | animal = Animal() 9 | animal.take('a ball') 10 | animal.play() 11 | -------------------------------------------------------------------------------- /code/python/class_private_method.py: -------------------------------------------------------------------------------- 1 | class Animal: 2 | def eat(self, food): 3 | if self._is_meat(food): 4 | print('Om nom nom') 5 | 6 | def _is_meat(self, food): 7 | return food == 'meat' 8 | 9 | Animal().eat('meat') 10 | -------------------------------------------------------------------------------- /code/ruby/class_field.rb: -------------------------------------------------------------------------------- 1 | class Animal 2 | def take(toy) 3 | @toy = toy 4 | end 5 | 6 | def play 7 | puts "I'm playing with #{@toy}" 8 | end 9 | end 10 | 11 | animal = Animal.new 12 | animal.take('a ball') 13 | animal.play 14 | -------------------------------------------------------------------------------- /code/ruby/class_private_method.rb: -------------------------------------------------------------------------------- 1 | class Animal 2 | def eat(food) 3 | puts 'Om nom nom' if meat? food 4 | end 5 | 6 | private 7 | 8 | def meat?(food) 9 | food == 'meat' 10 | end 11 | end 12 | 13 | Animal.new.eat('meat') 14 | -------------------------------------------------------------------------------- /code/java/LoopBreak.java: -------------------------------------------------------------------------------- 1 | class LoopBreak { 2 | public static void main(String[] args) { 3 | for (int i = 0; i < 3; i++) { 4 | System.out.println((i + 1) + ". Hi"); 5 | if (i == 1) 6 | break; 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/java/LoopNext.java: -------------------------------------------------------------------------------- 1 | class LoopNext { 2 | public static void main(String[] args) { 3 | for (int i = 0; i < 3; i++) { 4 | if (i == 1) 5 | continue; 6 | System.out.println((i + 1) + ". Hi"); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/javascript/class-inheritance.js: -------------------------------------------------------------------------------- 1 | class Animal { 2 | walk() { 3 | console.log("I'm walking"); 4 | } 5 | } 6 | 7 | class Dog extends Animal { 8 | sing() { 9 | console.log('Bark!'); 10 | } 11 | } 12 | 13 | new Dog().walk(); 14 | -------------------------------------------------------------------------------- /code/kotlin/ClassPrivateMethodAccessInstance.kts: -------------------------------------------------------------------------------- 1 | class Animal(private val name: String) { 2 | init { 3 | greet() 4 | } 5 | 6 | private fun greet() { 7 | println("Hello! My name is $name") 8 | } 9 | } 10 | 11 | Animal("Kelya") 12 | -------------------------------------------------------------------------------- /code/ruby/method_return.rb: -------------------------------------------------------------------------------- 1 | def multiple(a, b) 2 | a * b 3 | end 4 | puts multiple(2, 3) 5 | 6 | def divide(a, b) 7 | return 0 if a == 0 8 | a / b 9 | end 10 | puts divide 0, 10 11 | 12 | def default_value 13 | end 14 | p default_value 15 | -------------------------------------------------------------------------------- /code/java/ArrayIndexOfElement.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayIndexOfElement { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList("a", "b", "c"); 6 | System.out.println(arr.indexOf("c")); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/ClassDeclare.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | public void walk() { 3 | System.out.println("I'm walking"); 4 | } 5 | } 6 | 7 | class ClassDeclare { 8 | public static void main(String[] args) { 9 | new Animal().walk(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/java/ErrorWithAMessage.java: -------------------------------------------------------------------------------- 1 | class ErrorWithAMessage { 2 | public static void main(String[] args) { 3 | try { 4 | int i = 1 / 0; 5 | } catch (Exception e) { 6 | System.out.println(e.getMessage()); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/javascript/class-constructor.js: -------------------------------------------------------------------------------- 1 | class Animal { 2 | constructor(name) { 3 | this.name = name; 4 | } 5 | 6 | walk() { 7 | console.log(`My name is ${this.name} and I'm walking`); 8 | } 9 | } 10 | 11 | new Animal('Kelya').walk(); 12 | -------------------------------------------------------------------------------- /code/javascript/method-block-passing.js: -------------------------------------------------------------------------------- 1 | function mySelect(arr, filter) { 2 | const selected = []; 3 | arr.forEach(e => { 4 | if (filter(e)) selected.push(e); 5 | }); 6 | return selected; 7 | } 8 | console.log(mySelect([1, 5, 10], x => x < 6)); 9 | -------------------------------------------------------------------------------- /code/javascript/other-date.js: -------------------------------------------------------------------------------- 1 | const currentDate = new Date(); 2 | const day = currentDate.getDate(); 3 | const month = currentDate.getMonth() + 1; 4 | const year = currentDate.getFullYear(); 5 | const date = `${year}-${month}-${day}`; 6 | console.log(date); 7 | -------------------------------------------------------------------------------- /code/java/ArraySort.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArraySort { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList(4, 2, 3, 1); 6 | Collections.sort(arr); 7 | System.out.println(arr); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/java/ErrorThrow.java: -------------------------------------------------------------------------------- 1 | class ErrorThrow { 2 | public static void main(String[] args) { 3 | try { 4 | throw new Exception("An error!"); 5 | } catch (Exception e) { 6 | System.out.println(e.getMessage()); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/python/class_private_method_access_instance_var.py: -------------------------------------------------------------------------------- 1 | class Animal: 2 | def __init__(self, name): 3 | self.name = name 4 | self._greet() 5 | 6 | def _greet(self): 7 | print("Hello! My name is %s" % self.name) 8 | 9 | Animal('Kelya') 10 | -------------------------------------------------------------------------------- /code/python/other_structure_struct.py: -------------------------------------------------------------------------------- 1 | import collections 2 | 3 | class Customer(collections.namedtuple('Customer', 'name address')): 4 | def greeting(self): 5 | return "Hello %s!" % self.name 6 | 7 | print(Customer('Dave', '123 Main').greeting()) 8 | -------------------------------------------------------------------------------- /code/java/ArrayReduce.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayReduce { 4 | public static void main(String[] args) { 5 | int sum = 0; 6 | for (int n : Arrays.asList(1, 2, 3)) 7 | sum += n; 8 | System.out.println(sum); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/java/ClassClassMethod.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | public static void feed() { 3 | System.out.println("Om nom nom"); 4 | } 5 | } 6 | 7 | class ClassClassMethod { 8 | public static void main(String[] args) { 9 | Animal.feed(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/php/ConditionalSwitch.php: -------------------------------------------------------------------------------- 1 | arr = new ArrayList(); 6 | arr.add("first"); 7 | arr.add("second"); 8 | System.out.println(arr); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/java/FileDirPath.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | 3 | class FileDirPath { 4 | public static void main(String[] args) { 5 | URL location = FileDirPath.class.getProtectionDomain().getCodeSource().getLocation(); 6 | System.out.println(location.getFile()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/NumberFloat.java: -------------------------------------------------------------------------------- 1 | class NumberFloat { 2 | public static void main(String[] args) { 3 | System.out.println(9 / 2); 4 | System.out.println(9 / 2.0); 5 | System.out.println(Math.floor(9 / 2.0)); 6 | System.out.println(Math.round(9 / 2.0)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/javascript/class-get-set.js: -------------------------------------------------------------------------------- 1 | class Animal { 2 | setName(name) { 3 | this.name = name; 4 | } 5 | 6 | getName() { 7 | return this.name; 8 | } 9 | } 10 | 11 | const animal = new Animal(); 12 | animal.name = 'Kelya'; 13 | console.log(animal.name); 14 | -------------------------------------------------------------------------------- /code/java/OtherTime.java: -------------------------------------------------------------------------------- 1 | import java.util.Date; 2 | import java.text.SimpleDateFormat; 3 | 4 | class OtherTime { 5 | public static void main(String[] args) { 6 | String time = new SimpleDateFormat().format(new Date()); 7 | System.out.println(time); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/javascript/class-field.js: -------------------------------------------------------------------------------- 1 | class Animal { 2 | take(toy) { 3 | this.toy = toy; 4 | } 5 | 6 | play() { 7 | console.log(`I'm playing with ${this.toy}`); 8 | } 9 | } 10 | 11 | const animal = new Animal(); 12 | animal.take('a ball'); 13 | animal.play(); 14 | -------------------------------------------------------------------------------- /code/javascript/conditional-switch.js: -------------------------------------------------------------------------------- 1 | const foo = 'Hello!'; 2 | switch (foo) { 3 | case 10: case 20: 4 | console.log('10 or 20'); 5 | break; 6 | case 'And': console.log('case in one line'); break; 7 | default: 8 | console.log(`You gave me '${foo}'`); 9 | } 10 | -------------------------------------------------------------------------------- /code/javascript/other-import-file.js: -------------------------------------------------------------------------------- 1 | // other-file-to-import.js 2 | // module.exports = 3 | // class Import { 4 | // constructor() { 5 | // console.log('I am imported!'); 6 | // } 7 | // } 8 | 9 | const Import = require('./other-file-to-import'); 10 | new Import(); 11 | -------------------------------------------------------------------------------- /code/ruby/class_private_method_access_instance_var.rb: -------------------------------------------------------------------------------- 1 | class Animal 2 | def initialize(name) 3 | @name = name 4 | greet 5 | end 6 | 7 | private 8 | 9 | def greet 10 | puts "Hello! My name is #{@name}" 11 | end 12 | end 13 | 14 | Animal.new('Kelya') 15 | -------------------------------------------------------------------------------- /code/ruby/conditional_switch_as_else_if.rb: -------------------------------------------------------------------------------- 1 | score = 76 2 | grade = case 3 | when score < 60 then 'F' 4 | when score < 70 then 'D' 5 | when score < 80 then 'C' 6 | when score < 90 then 'B' 7 | else 'A' 8 | end 9 | puts grade 10 | -------------------------------------------------------------------------------- /code/java/FilePath.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | 3 | class FilePath { 4 | public static void main(String[] args) { 5 | URL location = FilePath.class.getProtectionDomain().getCodeSource().getLocation(); 6 | System.out.println(location.getFile() + "FilePath.class"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/ArrayUnique.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayUnique { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList("a", "b", "a"); 6 | Set unique = new LinkedHashSet<>(arr); 7 | System.out.println(unique); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/java/StringRegex.java: -------------------------------------------------------------------------------- 1 | import java.util.regex.*; 2 | 3 | class StringRegex { 4 | public static void main(String[] args) { 5 | System.out.println(Pattern.compile("^b").matcher("apple").find()); 6 | System.out.println(Pattern.compile("^a").matcher("apple").find()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /code/java/MathMaxMin.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class MathMaxMin { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList(1, 2, 3); 6 | System.out.println(Collections.min(arr)); 7 | System.out.println(Collections.max(arr)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/java/OtherDate.java: -------------------------------------------------------------------------------- 1 | import java.util.Date; 2 | import java.text.SimpleDateFormat; 3 | 4 | class OtherDate { 5 | public static void main(String[] args) { 6 | String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); 7 | System.out.println(date); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/ruby/class_method_call.rb: -------------------------------------------------------------------------------- 1 | class Animal 2 | def walk 3 | bark 4 | guard 5 | puts "I'm walking" 6 | end 7 | 8 | def bark 9 | puts 'Wuf!' 10 | end 11 | 12 | private 13 | 14 | def guard 15 | puts 'WUUUF!' 16 | end 17 | end 18 | 19 | Animal.new.walk 20 | -------------------------------------------------------------------------------- /code/javascript/method-return.js: -------------------------------------------------------------------------------- 1 | const multiple = (a, b) => a * b; 2 | console.log(multiple(2, 3)); 3 | 4 | function divide(a, b) { 5 | if (a === 0) return 0; 6 | return a / b; 7 | } 8 | console.log(divide(0, 10)); 9 | 10 | function defaultValue() {} 11 | console.log(defaultValue()); 12 | -------------------------------------------------------------------------------- /code/kotlin/ConditionalSwitch.kts: -------------------------------------------------------------------------------- 1 | val foo: Any = "Hello!" 2 | when (foo) { 3 | in 1..5 -> println("It's between 1 and 5") 4 | 10, 20 -> println("10 or 20") 5 | "And" -> println("case in one line") 6 | is String -> println("You passed a string '$foo'") 7 | else -> println("You gave me '$foo'") 8 | } -------------------------------------------------------------------------------- /code/kotlin/ClassField.kts: -------------------------------------------------------------------------------- 1 | class Animal { 2 | private var toy: String? = null 3 | 4 | fun take(toy: String) { 5 | this.toy = toy 6 | } 7 | 8 | fun play() { 9 | println("I'm playing with $toy") 10 | } 11 | } 12 | 13 | val animal = Animal() 14 | animal.take("a ball") 15 | animal.play() -------------------------------------------------------------------------------- /code/kotlin/OtherSafeNavigation.kts: -------------------------------------------------------------------------------- 1 | class Winner { 2 | val address: Address? = null 3 | } 4 | 5 | class Address { 6 | val zipcode: Int = 192187 7 | } 8 | 9 | val winner = Winner() 10 | val zip = winner.address?.zipcode 11 | println(zip?.let { "Zipcode is $it" } ?: "No prize without zipcode") 12 | -------------------------------------------------------------------------------- /code/java/ArrayGetFirstAndLast.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayGetFirstAndLast { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList("one", "two"); 6 | System.out.println(arr.get(0)); 7 | System.out.println(arr.get(arr.size() - 1)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /code/python/class_method_call.py: -------------------------------------------------------------------------------- 1 | class Animal: 2 | def walk(self): 3 | self.bark() 4 | self._guard() 5 | print("I'm walking") 6 | 7 | def bark(self): 8 | print('Wuf!') 9 | 10 | # Private by convention 11 | def _guard(self): 12 | print('WUUUF!') 13 | 14 | Animal().walk() 15 | -------------------------------------------------------------------------------- /code/ruby/conditional_switch.rb: -------------------------------------------------------------------------------- 1 | foo = 'Hello!' 2 | case foo 3 | when 1..5 4 | puts "It's between 1 and 5" 5 | when 10, 20 6 | puts '10 or 20' 7 | when 'And' then puts 'case in one line' 8 | when String 9 | puts "You passed a string '#{foo}'" 10 | else 11 | puts "You gave me '#{foo}'" 12 | end 13 | -------------------------------------------------------------------------------- /code/java/ErrorTryCatch.java: -------------------------------------------------------------------------------- 1 | class ErrorTryCatch { 2 | public static void main(String[] args) { 3 | try { 4 | int i = 1 / 0; 5 | } catch (Exception e) { 6 | System.out.println("Can't divide"); 7 | } finally { 8 | System.out.println("But that's ok"); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/kotlin/ClassMethodCall.kts: -------------------------------------------------------------------------------- 1 | class Animal { 2 | fun walk() { 3 | bark() 4 | guard() 5 | println("I'm walking") 6 | } 7 | 8 | private fun bark() { 9 | println("Wuf!") 10 | } 11 | 12 | private fun guard() { 13 | println("WUUUF!") 14 | } 15 | } 16 | 17 | Animal().walk() 18 | -------------------------------------------------------------------------------- /code/kotlin/MethodReturn.kts: -------------------------------------------------------------------------------- 1 | fun multiple(a: Int, b: Int): Int { 2 | return a * b 3 | } 4 | println(multiple(2, 3)) 5 | 6 | fun divide(a: Int, b: Int): Int { 7 | if (a == 0) return 0 8 | return a / b 9 | } 10 | println(divide(0, 10)) 11 | 12 | fun defaultValue() { 13 | } 14 | println(defaultValue()) 15 | -------------------------------------------------------------------------------- /code/python/method_block_passing.py: -------------------------------------------------------------------------------- 1 | def select(arr): 2 | yield from arr 3 | 4 | def select_filter(arr, filter): 5 | for a in arr: 6 | if filter(a): 7 | yield a 8 | 9 | print([x for x in select([1, 5, 10]) if x < 6]) 10 | print(list(select_filter([1, 5, 10], lambda x: x < 6))) 11 | -------------------------------------------------------------------------------- /code/kotlin/MethodBlockPassing.kts: -------------------------------------------------------------------------------- 1 | fun mySelect(arr: List, predicate: (T) -> Boolean): List { 2 | val selected = mutableListOf() 3 | for (a in arr) { 4 | if (predicate(a)) { 5 | selected.add(a) 6 | } 7 | } 8 | return selected 9 | } 10 | println(mySelect(listOf(1, 5, 10)) { it < 6 }) -------------------------------------------------------------------------------- /code/java/ArrayCount.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayCount { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList(1, 11, 111); 6 | int count = 0; 7 | for (int n : arr) 8 | if (n > 10) 9 | count++; 10 | System.out.println(count); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /code/java/HashAdd.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class HashAdd { 4 | public static void main(String[] args) { 5 | Map options = new HashMap(); 6 | options.put("fontSize", "10"); 7 | options.put("fontFamily", "Arial"); 8 | System.out.println(options); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/java/OtherImportFile.java: -------------------------------------------------------------------------------- 1 | // OtherFileToImport.java 2 | // class OtherFileToImport { 3 | // public OtherFileToImport() { 4 | // System.out.println("I am imported!"); 5 | // } 6 | // } 7 | 8 | class OtherImportFile { 9 | public static void main(String[] args) { 10 | new OtherFileToImport(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /code/java/HashSize.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class HashSize { 4 | public static void main(String[] args) { 5 | Map options = new HashMap() {{ 6 | put("fontSize", "10"); 7 | put("fontFamily", "Arial"); 8 | }}; 9 | System.out.println(options.size()); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/php/ClassInheritance.php: -------------------------------------------------------------------------------- 1 | walk(); 21 | -------------------------------------------------------------------------------- /code/java/ArrayMap.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayMap { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList(1, 5, 10, 20); 6 | List mapped = new ArrayList(); 7 | for (int n : arr) 8 | mapped.add(n * 2); 9 | System.out.println(mapped); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/java/ArrayIterateWithIndex.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayIterateWithIndex { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList("one", "two"); 6 | for (int i = 0; i < arr.size(); i++) { 7 | System.out.println(arr.get(i)); 8 | System.out.println(i); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/java/ArrayMulti.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayMulti { 4 | public static void main(String[] args) { 5 | List> arr = new ArrayList>(); 6 | arr.add(Arrays.asList("first", "second")); 7 | arr.add(Arrays.asList("third", "forth")); 8 | System.out.println(arr.get(1).get(1)); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/java/HashCreatePopulated.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class HashCreatePopulated { 4 | public static void main(String[] args) { 5 | Map options = new HashMap() {{ 6 | put("fontSize", "10"); 7 | put("fontFamily", "Arial"); 8 | }}; 9 | System.out.println(options); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/java/HashGetValue.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class HashGetValue { 4 | public static void main(String[] args) { 5 | Map options = new HashMap() {{ 6 | put("fontSize", "10"); 7 | put("fontFamily", "Arial"); 8 | }}; 9 | System.out.println(options.get("fonSize")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/python/class_mixin.py: -------------------------------------------------------------------------------- 1 | class Moving: 2 | def walk(self): 3 | print("%s is walking" % self.__class__.__name__) 4 | 5 | class Interacting: 6 | def talk(self): 7 | print("%s is talking" % self.__class__.__name__) 8 | 9 | class Human(Moving, Interacting): 10 | pass 11 | 12 | human = Human() 13 | human.walk() 14 | human.talk() 15 | -------------------------------------------------------------------------------- /code/python/conditional_switch.py: -------------------------------------------------------------------------------- 1 | foo = 'Hello!' 2 | if foo in range(1, 6): 3 | print("It's between 1 and 5") 4 | elif foo in (10, 20): 5 | print('10 or 20') 6 | elif foo == 'And': 7 | print('case in one line') 8 | elif isinstance(foo, str): 9 | print("You passed a string %r" % foo) 10 | else: 11 | print("You gave me %r" % foo) 12 | -------------------------------------------------------------------------------- /code/ruby/method_block_binding.rb: -------------------------------------------------------------------------------- 1 | class Action 2 | def self.say(&sentence) 3 | @name = 'Ann' 4 | puts sentence.call 5 | end 6 | end 7 | 8 | class Person 9 | def initialize(name) 10 | @name = name 11 | end 12 | 13 | def greet 14 | Action.say { "My name is #{@name}!" } 15 | end 16 | end 17 | 18 | Person.new('Alex').greet 19 | -------------------------------------------------------------------------------- /code/java/ArraySelect.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArraySelect { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList(1, 5, 10, 20); 6 | List all = new ArrayList(); 7 | for (int n : arr) 8 | if (n % 2 == 0) 9 | all.add(n); 10 | System.out.println(all); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /code/java/HashIsInclude.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class HashIsInclude { 4 | public static void main(String[] args) { 5 | Map options = new HashMap() {{ 6 | put("fontSize", "10"); 7 | put("fontFamily", "Arial"); 8 | }}; 9 | System.out.println(options.containsKey("fontSize")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/python/method_block_binding.py: -------------------------------------------------------------------------------- 1 | class Action: 2 | name = 'Ann' 3 | 4 | @staticmethod 5 | def say(sentence): 6 | print(sentence()) 7 | 8 | 9 | class Person: 10 | def __init__(self, name): 11 | self.name = name 12 | 13 | def greet(self): 14 | Action.say(lambda: "My name is %s!" % self.name) 15 | 16 | 17 | Person('Alex').greet() 18 | -------------------------------------------------------------------------------- /code/java/MethodMultiArg.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class MethodMultiArg { 4 | public static void main(String[] args) { 5 | new MethodMultiArg().sweets(true, "snickers", "twix", "bounty"); 6 | } 7 | 8 | public void sweets(boolean buy, String... brands) { 9 | if (buy) 10 | System.out.println(Arrays.toString(brands)); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /code/java/MethodReturn.java: -------------------------------------------------------------------------------- 1 | class MethodReturn { 2 | public static void main(String[] args) { 3 | MethodReturn obj = new MethodReturn(); 4 | System.out.println(obj.divide(0, 10)); 5 | System.out.println(obj.divide(10, 5)); 6 | } 7 | 8 | public int divide(int a, int b) { 9 | if (a == 0) 10 | return 0; 11 | return a / b; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /code/ruby/class_mixin.rb: -------------------------------------------------------------------------------- 1 | module Moving 2 | def walk 3 | puts "#{self.class.name} is walking" 4 | end 5 | end 6 | 7 | module Interacting 8 | def talk 9 | puts "#{self.class.name} is talking" 10 | end 11 | end 12 | 13 | class Human 14 | include Moving 15 | include Interacting 16 | end 17 | 18 | human = Human.new 19 | human.walk 20 | human.talk 21 | -------------------------------------------------------------------------------- /code/java/ArrayConcat.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayConcat { 4 | public static void main(String[] args) { 5 | List arr1 = Arrays.asList(1, 2); 6 | List arr2 = Arrays.asList(3, 4); 7 | List concated = new ArrayList(arr1); 8 | concated.addAll(arr2); 9 | System.out.println(concated); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/java/ArrayFind.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayFind { 4 | public static void main(String[] args) { 5 | List arr = Arrays.asList(1, 5, 10, 20); 6 | int first = 0; 7 | for (int n : arr) { 8 | if (n % 2 == 0) { 9 | first = n; 10 | break; 11 | } 12 | } 13 | System.out.println(first); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /code/java/ClassInheritance.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | public void walk() { 3 | System.out.println("I'm walking"); 4 | } 5 | } 6 | 7 | class Dog extends Animal { 8 | public void sing() { 9 | System.out.println("Bark!"); 10 | } 11 | } 12 | 13 | class ClassInheritance { 14 | public static void main(String[] args) { 15 | new Dog().walk(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /code/kotlin/ClassMixin.kts: -------------------------------------------------------------------------------- 1 | interface Moving { 2 | fun walk() { 3 | println("${this::class.simpleName} is walking") 4 | } 5 | } 6 | 7 | interface Interacting { 8 | fun talk() { 9 | println("${this::class.simpleName} is talking") 10 | } 11 | } 12 | 13 | class Human : Moving, Interacting 14 | 15 | val human = Human() 16 | human.walk() 17 | human.talk() 18 | -------------------------------------------------------------------------------- /code/java/ConditionalSwitch.java: -------------------------------------------------------------------------------- 1 | class ConditionalSwitch { 2 | public static void main(String[] args) { 3 | String s = "Hello!"; 4 | switch (s) { 5 | case "Bye!": 6 | System.out.println("wrong"); 7 | break; 8 | case "Hello!": 9 | System.out.println("right"); 10 | break; 11 | default: break; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /code/kotlin/MethodBlockBinding.kts: -------------------------------------------------------------------------------- 1 | class Action { 2 | companion object { 3 | private var name: String = "Ann" 4 | fun say(sentence: () -> String) { 5 | println(sentence()) 6 | } 7 | } 8 | } 9 | 10 | class Person(private val name: String) { 11 | fun greet() { 12 | Action.say { "My name is $name!" } 13 | } 14 | } 15 | 16 | Person("Alex").greet() 17 | -------------------------------------------------------------------------------- /code/php/ClassPrivateMethod.php: -------------------------------------------------------------------------------- 1 | isMeat($food)) 8 | echo "Om nom nom"; 9 | } 10 | 11 | private function isMeat(string $food) : bool 12 | { 13 | return strcmp($food, "meat") == 0; 14 | } 15 | } 16 | 17 | (new AnimalI())->eat("meat"); 18 | -------------------------------------------------------------------------------- /code/ruby/method_init_in_runtime.rb: -------------------------------------------------------------------------------- 1 | class ProccessElements 2 | def self.element(el_name) 3 | define_method "#{el_name}_element" do |content| 4 | "<#{el_name}>#{content}" 5 | end 6 | end 7 | end 8 | 9 | class HtmlELements < ProccessElements 10 | element :div 11 | element :span 12 | end 13 | 14 | puts HtmlELements.new.div_element('hello') 15 | -------------------------------------------------------------------------------- /code/java/FileParentDirPath.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.io.*; 3 | 4 | class FileParentDirPath { 5 | public static void main(String[] args) { 6 | URL location = FileParentDirPath.class.getProtectionDomain().getCodeSource().getLocation(); 7 | String parentPath = new File(location.getFile()).getParent(); 8 | System.out.println(parentPath); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/php/ClassConstructor.php: -------------------------------------------------------------------------------- 1 | name = $name; 10 | } 11 | 12 | public function walk() 13 | { 14 | echo "My name is {$this->name} and I'm walking"; 15 | } 16 | } 17 | 18 | $animal = new AnimalB("Kelya"); 19 | $animal->walk(); -------------------------------------------------------------------------------- /code/ruby/other_safe_navigation.rb: -------------------------------------------------------------------------------- 1 | class Winner 2 | attr_reader :address 3 | 4 | def initialize 5 | # @address = Address.new 6 | end 7 | end 8 | 9 | class Address 10 | attr_reader :zipcode 11 | 12 | def initialize 13 | @zipcode = 192187 14 | end 15 | end 16 | 17 | zip = Winner.new.address&.zipcode 18 | puts zip ? "Zipcode is #{zip}" : "No prize without zipcode" 19 | -------------------------------------------------------------------------------- /code/php/ClassField.php: -------------------------------------------------------------------------------- 1 | toy = $toy; 11 | } 12 | 13 | public function play() 14 | { 15 | echo "I'm playing with " . $this->toy; 16 | } 17 | } 18 | 19 | $animal = new AnimalD(); 20 | $animal->take("a ball"); 21 | $animal->play(); 22 | -------------------------------------------------------------------------------- /code/php/ClassGetSet.php: -------------------------------------------------------------------------------- 1 | name = $name; 10 | } 11 | 12 | public function getName() : string 13 | { 14 | return $this->name; 15 | } 16 | } 17 | 18 | $animal = new AnimalE(); 19 | $animal->setName("Kelya"); 20 | echo $animal->getName(); 21 | -------------------------------------------------------------------------------- /code/php/ClassPrivateMethodAccessInstance.php: -------------------------------------------------------------------------------- 1 | name = $name; 10 | $this->greet(); 11 | } 12 | 13 | private function greet() 14 | { 15 | echo "Hello! My name is " . $this->name; 16 | } 17 | } 18 | 19 | new AnimalJ("Kelya"); 20 | -------------------------------------------------------------------------------- /code/java/ClassPrivateMethod.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | public void eat(String food) { 3 | if (isMeat(food)) 4 | System.out.println("Om nom nom"); 5 | } 6 | 7 | private boolean isMeat(String food) { 8 | return food.equals("meat"); 9 | } 10 | } 11 | 12 | class ClassPrivateMethod { 13 | public static void main(String[] args) { 14 | new Animal().eat("meat"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /code/java/ClassConstructor.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | private String name; 3 | 4 | public Animal(String name) { 5 | this.name = name; 6 | } 7 | 8 | public void walk() { 9 | System.out.println("My name is " + this.name + " and I'm walking"); 10 | } 11 | } 12 | 13 | class ClassConstructor { 14 | public static void main(String[] args) { 15 | new Animal("Kelya").walk(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /code/java/FileWrite.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class FileWrite { 4 | public static void main(String[] args) throws IOException { 5 | String filePath = System.getProperty("user.dir") + "/code/output.txt"; 6 | try (Writer writer = new BufferedWriter(new OutputStreamWriter( 7 | new FileOutputStream(filePath), "utf-8"))) { 8 | writer.write("Some glorious content"); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /code/ruby/method_block_passing.rb: -------------------------------------------------------------------------------- 1 | def my_select(arr) 2 | selected = [] 3 | arr.each do |a| 4 | selected.push a if yield(a) 5 | end 6 | selected 7 | end 8 | puts my_select [1, 5, 10] { |x| x < 6 } 9 | 10 | 11 | def my_select(arr, &filter) 12 | selected = [] 13 | arr.each do |a| 14 | selected.push a if filter.call(a) 15 | end 16 | selected 17 | end 18 | puts my_select [1, 5, 10] { |x| x < 6 } 19 | -------------------------------------------------------------------------------- /code/java/FileSisterDirPath.java: -------------------------------------------------------------------------------- 1 | import java.net.*; 2 | import java.io.*; 3 | 4 | class FileSisterDirPath { 5 | public static void main(String[] args) throws IOException { 6 | URL location = FileSisterDirPath.class.getProtectionDomain().getCodeSource().getLocation(); 7 | String parentPath = new File(location.getFile() + ".." + "/java").getCanonicalPath(); 8 | System.out.println(parentPath); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /code/php/ClassMethodCall.php: -------------------------------------------------------------------------------- 1 | bark(); 8 | $this->guard(); 9 | echo "I'm walking\n"; 10 | } 11 | 12 | public function bark() 13 | { 14 | echo "Wuf!\n"; 15 | } 16 | 17 | private function guard() 18 | { 19 | echo "WUUUF!\n"; 20 | } 21 | } 22 | 23 | (new AnimalH())->walk(); 24 | -------------------------------------------------------------------------------- /code/java/ArrayDeleteElement.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class ArrayDeleteElement { 4 | public static void main(String[] args) { 5 | List arr = new LinkedList(Arrays.asList("a", "b", "c")); 6 | Iterator iter = arr.iterator(); 7 | while(iter.hasNext()) { 8 | if(iter.next().equalsIgnoreCase("b")) 9 | iter.remove(); 10 | } 11 | System.out.println(arr); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /code/java/TypeNullTrueFalse.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class TypeNullTrueFalse { 4 | public static void main(String[] args) { 5 | List emptyArray = new ArrayList(); 6 | System.out.println(emptyArray.isEmpty()); 7 | 8 | String emptyString = ""; 9 | System.out.println(emptyString.isEmpty()); 10 | 11 | String nullVar = null; 12 | System.out.println(nullVar == null); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /code/java/ClassField.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | private String toy; 3 | 4 | public void take(String toy) { 5 | this.toy = toy; 6 | } 7 | 8 | public void play() { 9 | System.out.println("I'm playing with " + this.toy); 10 | } 11 | } 12 | 13 | class ClassField { 14 | public static void main(String[] args) { 15 | Animal animal = new Animal(); 16 | animal.take("a ball"); 17 | animal.play(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /code/java/ClassPrivateMethodAccessInstance.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | private String name; 3 | 4 | public Animal(String name) { 5 | this.name = name; 6 | greet(); 7 | } 8 | 9 | private void greet() { 10 | System.out.println("Hello! My name is " + this.name); 11 | } 12 | } 13 | 14 | class ClassPrivateMethodAccessInstance { 15 | public static void main(String[] args) { 16 | new Animal("Kelya"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /code/java/ClassGetSet.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | private String name; 3 | 4 | public void setName(String name) { 5 | this.name = name; 6 | } 7 | 8 | public String getName() { 9 | return this.name; 10 | } 11 | } 12 | 13 | class ClassGetSet { 14 | public static void main(String[] args) { 15 | Animal animal = new Animal(); 16 | animal.setName("Kelya"); 17 | System.out.println(animal.getName()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /code/java/OtherStructureConstantList.java: -------------------------------------------------------------------------------- 1 | enum Color { 2 | RED("#FF0000"), 3 | GREEN("#00FF00"); 4 | 5 | private String color; 6 | 7 | private Color(String color) { 8 | this.color = color; 9 | } 10 | 11 | public String toString() { 12 | return color; 13 | } 14 | } 15 | 16 | class OtherStructureConstantList { 17 | public static void main(String[] args) { 18 | System.out.println(Color.GREEN); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /code/java/ClassMethodCall.java: -------------------------------------------------------------------------------- 1 | class Animal { 2 | public void walk() { 3 | bark(); 4 | guard(); 5 | System.out.println("I'm walking"); 6 | } 7 | 8 | public void bark() { 9 | System.out.println("Wuf!"); 10 | } 11 | 12 | private void guard() { 13 | System.out.println("WUUUF!"); 14 | } 15 | } 16 | 17 | class ClassMethodCall { 18 | public static void main(String[] args) { 19 | new Animal().walk(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /code/python/method_init_in_runtime.py: -------------------------------------------------------------------------------- 1 | class ProccessElements: 2 | def __init__(self): 3 | def element(el_name): 4 | def render(content): 5 | return '<{0}>{1}'.format(el_name, content) 6 | return render 7 | 8 | for el_name in self.elements: 9 | setattr(self, el_name, element(el_name)) 10 | 11 | 12 | class HtmlELements(ProccessElements): 13 | elements = ('div', 'span') 14 | 15 | print(HtmlELements().div('hello')) 16 | -------------------------------------------------------------------------------- /code/java/HashIterate.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class HashIterate { 4 | public static void main(String[] args) { 5 | Map options = new HashMap() {{ 6 | put("fontSize", "10"); 7 | put("fontFamily", "Arial"); 8 | }}; 9 | for (Map.Entry entry : options.entrySet()) { 10 | System.out.println(entry.getKey()); 11 | System.out.println(entry.getValue()); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - 'vendor/**/*' 5 | - 'db/**/*' 6 | - 'config/**/*' 7 | - 'vagrant/**/*' 8 | - 'bin/**/*' 9 | - 'code/ruby/**/*' 10 | 11 | Metrics/LineLength: 12 | Max: 100 13 | 14 | Metrics/AbcSize: 15 | Max: 25 16 | 17 | Metrics/MethodLength: 18 | Max: 15 19 | 20 | Style/Documentation: 21 | Enabled: false 22 | 23 | Style/Encoding: 24 | Enabled: false 25 | 26 | Style/RescueModifier: 27 | Enabled: false 28 | -------------------------------------------------------------------------------- /code/javascript/method-block-binding.js: -------------------------------------------------------------------------------- 1 | class Action { 2 | static say(sentence) { 3 | console.log(sentence()); 4 | } 5 | } 6 | 7 | class Person { 8 | constructor(name) { 9 | this.name = name; 10 | } 11 | 12 | greet() { 13 | try { 14 | Action.say(function() { `My name is ${this.name}!`; }); 15 | } catch (err) { 16 | console.log(err.message); 17 | } 18 | Action.say(() => `My name is ${this.name}!`); 19 | } 20 | } 21 | 22 | new Person('Alex').greet(); 23 | -------------------------------------------------------------------------------- /code/java/ClassHasMethod.java: -------------------------------------------------------------------------------- 1 | import java.lang.reflect.*; 2 | 3 | class Animal { 4 | public void walk() { 5 | System.out.println("I'm walking"); 6 | } 7 | } 8 | 9 | class ClassHasMethod { 10 | public static void main(String[] args) { 11 | Animal animal = new Animal(); 12 | boolean hasMethod = false; 13 | for (Method m : animal.getClass().getMethods()) { 14 | if (m.getName().equals("walk")) { 15 | hasMethod = true; 16 | break; 17 | } 18 | } 19 | System.out.println(hasMethod); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /code/python/type_null_true_false.py: -------------------------------------------------------------------------------- 1 | def check(label, fn, values): 2 | print(label) 3 | for value in values: 4 | try: 5 | result = 'true' if fn(value) else 'false' 6 | except TypeError as e: 7 | result = 'error: %s' % e 8 | print(" %-9r - %s" % (value, result)) 9 | print() 10 | 11 | values = ['string', '', [1, 2, 3], [], 5, 0, True, False, None] 12 | 13 | check('if value:', lambda v: v, values) 14 | check('if value is None:', lambda v: v is None, values) 15 | check('if len(value):', lambda v: len(v), values) 16 | -------------------------------------------------------------------------------- /code/ruby/type_null_true_false.rb: -------------------------------------------------------------------------------- 1 | def check(label, fn, values) 2 | puts label 3 | values.each do |value| 4 | begin 5 | result = fn.call(value) ? 'true' : 'false' 6 | rescue NoMethodError => e 7 | result = "error: #{e}" 8 | end 9 | puts format(" %-9p - %s", value, result) 10 | end 11 | puts '' 12 | end 13 | 14 | values = ['string', '', [1, 2, 3], [], 5, 0, true, false, nil] 15 | 16 | check('if value:', -> (v) { v }, values) 17 | check('if value.nil?:', -> (v) { v.nil? }, values) 18 | check('if value.empty?:', -> (v) { v.empty? }, values) 19 | -------------------------------------------------------------------------------- /code/java/OtherRunCommand.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class OtherRunCommand { 4 | public static void main(String[] args) throws IOException, InterruptedException { 5 | String result = ""; 6 | ProcessBuilder ps = new ProcessBuilder("java", "-version"); 7 | ps.redirectErrorStream(true); 8 | Process pr = ps.start(); 9 | BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream())); 10 | String line; 11 | while ((line = in.readLine()) != null) 12 | result += line + "\n"; 13 | pr.waitFor(); 14 | in.close(); 15 | System.out.println(result); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /code/java/FileRead.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class FileRead { 4 | public static void main(String[] args) throws IOException { 5 | String filePath = System.getProperty("user.dir") + "/code/file.txt"; 6 | String content; 7 | try (BufferedReader br = new BufferedReader(new FileReader(filePath))) { 8 | StringBuilder sb = new StringBuilder(); 9 | String line = br.readLine(); 10 | while (line != null) { 11 | sb.append(line); 12 | sb.append(System.lineSeparator()); 13 | line = br.readLine(); 14 | } 15 | content = sb.toString(); 16 | } 17 | System.out.println(content); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /source/_content.haml: -------------------------------------------------------------------------------- 1 | %ul.list-unstyled 2 | - data.code.each_with_index do |section, index| 3 | - next if section_empty?(section, lang1, lang2) 4 | - next unless filter.call(index, data.code.size / 2) 5 | 6 | %li.content 7 | %strong 8 | %a.scroll.section{href: sanitize("##{section.first}"), title: section.first}= section.first 9 | %ul 10 | - section.last.each do |header, lang_to_filenames| 11 | - next if no_files?(lang1, lang_to_filenames[lang1]) && no_files?(lang2, lang_to_filenames[lang2]) 12 | %li 13 | %a.scroll{href: sanitize("##{section.first}_#{header}"), title: header}= header 14 | 15 | -------------------------------------------------------------------------------- /source/layouts/layout.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | %meta{:charset => "utf-8"}/ 5 | %meta{:content => "IE=edge,chrome=1", "http-equiv" => "X-UA-Compatible"}/ 6 | %title Language compare 7 | = stylesheet_link_tag :all, "syntax" 8 | 9 | %body 10 | #top 11 | %span#root-url{:hidden => ""} #{config[:root_url]} 12 | %a{href: 'https://github.com/evmorov/lang-compare'} 13 | %img{alt: 'Fork me on GitHub', 14 | src: 'https://github.blog/wp-content/uploads/2008/12/forkme_right_gray_6d6d6d.png?resize=149%2C149', 15 | style: 'position: absolute; top: 0; right: 0; border: 0;'} 16 | = yield 17 | #footer 18 | = javascript_include_tag :all 19 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # If you do not have OpenSSL installed, update 4 | # the following line to use "http://" instead 5 | source 'https://rubygems.org' 6 | 7 | gem 'middleman', '~> 4.1' 8 | 9 | # For faster file watcher updates on Windows: 10 | gem 'wdm', '~> 0.1', platforms: %i[mswin mingw] 11 | 12 | # Windows does not come with time zone data 13 | gem 'tzinfo-data', platforms: %i[mswin mingw jruby] 14 | 15 | gem 'bootstrap-sass', '~> 3.3' 16 | gem 'jquery-middleman', '~> 3.1' 17 | gem 'middleman-deploy', '~> 2.0.0.pre.alpha' 18 | gem 'middleman-sprockets', '~> 4.0.0.rc' 19 | gem 'middleman-syntax' 20 | gem 'net-ftp' 21 | 22 | group :development do 23 | gem 'rake' 24 | gem 'rubocop' 25 | end 26 | -------------------------------------------------------------------------------- /config.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | activate :directory_indexes 4 | activate :sprockets 5 | activate :syntax 6 | set :relative_links, true 7 | set :haml, ugly: true 8 | 9 | configure :build do 10 | activate :minify_css 11 | activate :minify_javascript 12 | activate :asset_hash 13 | activate :relative_assets 14 | config[:root_url] = '/lang-compare' 15 | end 16 | 17 | configure :development do 18 | config[:root_url] = '/' 19 | end 20 | 21 | activate :deploy do |deploy| 22 | deploy.deploy_method = :git 23 | end 24 | 25 | def template_proxy(url, lang1, lang2, langs) 26 | proxy(url, 'template', locals: { lang1: lang1, lang2: lang2, langs: langs }, ignore: true) 27 | end 28 | 29 | langs = %w[Ruby JavaScript Java Python PHP Kotlin] 30 | langs.each do |lang1| 31 | langs.each do |lang2| 32 | url = "#{lang1.delete(' ').downcase}-#{lang2.delete(' ').downcase}.html" 33 | template_proxy url, lang1, lang2, langs 34 | end 35 | end 36 | template_proxy 'index.html', 'Ruby', 'Python', langs # languages by default 37 | -------------------------------------------------------------------------------- /source/stylesheets/all.css.scss: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | @import "bootstrap-sprockets"; 3 | @import "bootstrap"; 4 | 5 | .highlight { 6 | font-size: 0.9em; 7 | } 8 | 9 | .page-header1 { 10 | a:hover { 11 | text-decoration: none; 12 | } 13 | } 14 | 15 | .compare-header3 { 16 | padding-bottom: 10px; 17 | } 18 | 19 | .compare-header4 { 20 | padding-bottom: 5px; 21 | } 22 | 23 | #top-link-block { 24 | &.affix-top { 25 | position: absolute; 26 | right: 10px; 27 | } 28 | 29 | &.affix { 30 | position: fixed; 31 | bottom: 18px; 32 | right: 10px; 33 | } 34 | } 35 | 36 | li.content { 37 | margin-top: 10px; 38 | } 39 | 40 | .language-list { 41 | margin-left: -15px; 42 | } 43 | 44 | #footer { 45 | margin-bottom: 50px; 46 | } 47 | 48 | .link-unstyled { 49 | color: inherit; 50 | text-decoration: inherit; 51 | } 52 | 53 | pre.unstyled { 54 | border: 0; 55 | background-color: transparent; 56 | } 57 | 58 | .output { 59 | margin-top: 0; 60 | margin-left: 0; 61 | padding-top: 0; 62 | padding-left: 0; 63 | font-size: 0.9em; 64 | } 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Evgeny Morozov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /source/javascripts/main.js: -------------------------------------------------------------------------------- 1 | if ($(window).height() + 100 < $(document).height()) { 2 | $("#top-link-block") 3 | .removeClass("hidden") 4 | .affix({ offset: { top: 1100 } }); 5 | } 6 | 7 | const scroll = (element, toTop = false) => { 8 | $(element).click(function (event) { 9 | event.preventDefault(); 10 | const href = $.attr(this, "href"); 11 | $("html, body").animate({ scrollTop: $(href).offset().top }, 400, () => { 12 | window.location.hash = toTop ? "" : href; 13 | }); 14 | return false; 15 | }); 16 | }; 17 | 18 | scroll("a.scrollTop", true); 19 | scroll("a.scroll"); 20 | 21 | $(".lang-item").click(function (e) { 22 | const langUrl1 = $(this).data("lang-url"); 23 | const side1 = $(this).parent().parent().data("lang-side"); 24 | const side2 = side1 === 1 ? 2 : 1; 25 | const langUrl2 = $(`div[data-lang-side='${side2}']`) 26 | .find("span.lang-selected") 27 | .data("lang-url"); 28 | 29 | let targetUrl; 30 | if (side1 === 1) { 31 | targetUrl = `/${langUrl1}-${langUrl2}`; 32 | } else { 33 | targetUrl = `/${langUrl2}-${langUrl1}`; 34 | } 35 | 36 | const rootUrl = $("#root-url").html(); 37 | if (rootUrl !== "/") { 38 | targetUrl = `${rootUrl}${targetUrl}`; 39 | } 40 | 41 | window.location.href = targetUrl; 42 | e.preventDefault(); 43 | }); 44 | -------------------------------------------------------------------------------- /helpers/custom_helpers.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module CustomHelpers 4 | Example = Struct.new(:code, :output) 5 | 6 | def examples(language, filenames) 7 | return [] unless filenames 8 | 9 | examples = [] 10 | each_filename(filenames) do |filename, folder| 11 | file_content = File.read(code_file_path(language, filename, folder)) rescue next 12 | output = File.read(code_file_path(language, "#{filename}.out", folder)) rescue nil 13 | highlighted_code = code(language) { file_content } 14 | highlighted_code = add_version(highlighted_code, folder) if !folder.empty? && folder != '.' 15 | examples.push Example.new(highlighted_code, output) 16 | end 17 | examples 18 | end 19 | 20 | def sanitize(str) 21 | str.tr(' /,', '_').tr('()?', '').downcase 22 | end 23 | 24 | def urlize(str) 25 | str.delete(' ').downcase 26 | end 27 | 28 | def section_empty?(section, lang1, lang2) 29 | section.last.each_value do |filenames| 30 | return false unless no_files?(lang1, filenames[lang1]) && no_files?(lang2, filenames[lang2]) 31 | end 32 | true 33 | end 34 | 35 | def no_files?(lang, filenames) 36 | return true unless filenames 37 | 38 | each_filename(filenames) do |filename, folder| 39 | return false if File.exist? code_file_path(lang, filename, folder) 40 | end 41 | true 42 | end 43 | 44 | private 45 | 46 | def add_version(code, version) 47 | version_tag = "[ #{version} ]" 48 | version_tag + code 49 | end 50 | 51 | def each_filename(filenames, &block) 52 | if filenames.is_a? Hash 53 | filenames.each { |folder, filename| block.call(filename, folder) } 54 | else 55 | block.call(filenames, '') 56 | end 57 | end 58 | 59 | def code_file_path(language, filename, folder = '') 60 | File.join(Dir.pwd, 'code', language, folder, filename) 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'open3' 4 | 5 | CODE_DIR = File.join(File.dirname(__FILE__), 'code') 6 | 7 | task default: [:run] 8 | task run: %i[clean run_java run_javascript run_ruby run_python run_php] 9 | 10 | task :run_java do 11 | puts 'Executing java files' 12 | Dir.glob File.join(CODE_DIR, '**', '*.java') do |filepath| 13 | result = run_file("javac -cp #{CODE_DIR}/java #{filepath}", "#{filepath}.out") 14 | next unless result.to_i.zero? # error occurred while compiling 15 | 16 | class_name = File.basename(filepath).gsub('.java', '') 17 | run_file("java -cp #{CODE_DIR}/java #{class_name}", "#{filepath}.out") 18 | end 19 | puts "\n\n" 20 | end 21 | 22 | task :run_ruby do 23 | puts 'Executing ruby files' 24 | run_scripts('ruby', 'rb') 25 | puts "\n\n" 26 | end 27 | 28 | task :run_javascript do 29 | puts 'Executing js files' 30 | run_scripts('node --use_strict', 'js') 31 | puts "\n\n" 32 | end 33 | 34 | task :run_python do 35 | puts 'Executing python files' 36 | run_scripts('python3', 'py') 37 | puts "\n\n" 38 | end 39 | 40 | task :run_php do 41 | puts 'Executing php files' 42 | run_scripts('php', 'php') 43 | puts "\n\n" 44 | end 45 | 46 | task :run_kotlin do 47 | puts 'Executing kotlin files' 48 | run_scripts('kotlinc -script', 'kts') 49 | puts "\n\n" 50 | end 51 | 52 | def run_scripts(command, ext) 53 | Dir.glob File.join(CODE_DIR, '**', "*.#{ext}") do |filepath| 54 | run_file("#{command} #{filepath}", "#{filepath}.out") 55 | end 56 | end 57 | 58 | def run_file(command, out_path) 59 | print '.' 60 | Open3.popen2e(command) do |_stdin, stdout_and_stderr, _wait_thr| 61 | File.write(out_path, stdout_and_stderr.read) 62 | end 63 | end 64 | 65 | task :clean do 66 | [ 67 | '*.class', 68 | '*.out', 69 | '*.pyc', 70 | 'output.txt' 71 | ].each do |file| 72 | FileUtils.rm Dir.glob(File.join(CODE_DIR, '**', file)) 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /source/template.haml: -------------------------------------------------------------------------------- 1 | - lang1_urlized = urlize(lang1) 2 | - lang2_urlized = urlize(lang2) 3 | 4 | .container-fluid 5 | %h1.page-header1 6 | = link_to 'Language compare', config[:root_url] 7 | 8 | .row 9 | - [lang1, lang2].each_with_index do |lang_selected, index| 10 | .col-md-6 11 | .dropdown{"data-lang-side" => index + 1} 12 | %button.btn.btn-link.btn-lg.language-list.dropdown-toggle{"aria-expanded" => "true", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"} 13 | %span.lang-selected{"data-lang-url" => urlize(lang_selected)} #{lang_selected} 14 | %span.caret 15 | %ul.dropdown-menu{"aria-labelledby" => "dropdownMenu1"} 16 | - langs.each do |lang| 17 | %li.lang-item{"data-lang-url" => urlize(lang)} 18 | = link_to lang 19 | 20 | .row 21 | .col-md-6 22 | = partial(:content, locals: {filter: -> (hash_index, hash_size) { hash_index < hash_size }, lang1: lang1_urlized, lang2: lang2_urlized }) 23 | .col-md-6 24 | = partial(:content, locals: {filter: -> (hash_index, hash_size) { hash_index >= hash_size }, lang1: lang1_urlized, lang2: lang2_urlized }) 25 | 26 | .row 27 | .col-md-6 28 | %h2.compare-header2 #{lang1} 29 | .col-md-6 30 | %h2.compare-header2 #{lang2} 31 | 32 | - data.code.each do |section| 33 | - next if section_empty?(section, lang1_urlized, lang2_urlized) 34 | 35 | %h3.compare-header3{id: sanitize(section.first)}= section.first 36 | - section.last.each do |header, langs_to_filenames| 37 | - next if no_files?(lang1_urlized, langs_to_filenames[lang1_urlized]) && no_files?(lang2_urlized, langs_to_filenames[lang2_urlized]) 38 | 39 | %h4.compare-header4 40 | = header 41 | %small 42 | - bookmark = sanitize("#{section.first}_#{header}") 43 | %a.link-unstyled{href: "##{bookmark}", id: bookmark} 44 | %i.glyphicon.glyphicon-link 45 | .row 46 | - [lang1_urlized, lang2_urlized].each do |lang| 47 | .col-md-6 48 | - examples = examples(lang, langs_to_filenames[lang]) 49 | - if examples.any? 50 | - examples.each do |example| 51 | = example.code 52 | %pre.unstyled.output.text-muted= escape_html(example.output) 53 | - else 54 | = 'No easy way to do that' 55 | 56 | %span#top-link-block 57 | %a.scrollTop.well.well-sm{href: '#top'} 58 | %i.glyphicon.glyphicon-chevron-up 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Compare syntax of programming languages 2 | 3 | The web app provides side-by-side examples of syntax differences between programming languages. You can use it as a cheatsheet or as a learning material to learn one of them through another. Creating these examples I tried to use the most used and the cleanest solutions. 4 | 5 | All examples are executable. You can copy and launch them without changes. It helps to understand what the code is doing easily. 6 | 7 | View web app [here](https://evmorov.github.io/lang-compare). 8 | 9 | Created with: 10 | 11 | - [Middleman](https://middlemanapp.com) 12 | - [Bootstrap](https://getbootstrap.com) 13 | 14 | ## Notes 15 | 16 | All languages: 17 | 18 | - It's possible to achieve anything with any language (especially with a library). However when a solution is really long and difficult to read it's better to not provide it 19 | - Every task can be solved in different ways but it's preferable to provide not more than one the most used example 20 | 21 | Java and Kotlin: 22 | 23 | - 2 spaces is used to make the code more concise 24 | 25 | ## What's next 26 | 27 | Add more languages: 28 | 29 | * Ruby - Elixir 30 | * Ruby - Crystal 31 | * Java - C# 32 | * JavaScript - TypeScript 33 | 34 | ## Development 35 | 36 | Install ruby: 37 | 38 | $ ruby --version 39 | 40 | Install dependencies: 41 | 42 | $ bundle 43 | 44 | Run the app in localhost (http://localhost:4567): 45 | 46 | $ bundle exec middleman 47 | 48 | To generate outputs below the examples: 49 | 50 | 1. Install all interpreters/compilers needed 51 | 2. `$ rake` 52 | 53 | To add a new language: 54 | 55 | 1. Add the language to `langs` variable to `config.rb` 56 | 2. Add a rake task to `Rakefile` to run all the examples to produce output files that are included to the final html 57 | 3. Add examples 58 | 59 | To add an example: 60 | 61 | 1. Modify `data/code.yml` 62 | 2. Add files to `code/` folder 63 | 64 | ### Example for a specific version 65 | 66 | Where can I provide a version? 67 | 68 | - Python 2 vs Python 3 69 | - Java 7 vs Java 8 70 | - ES5 vs ES6 71 | - New features that are not standard de-facto yet 72 | 73 | #### Examples 74 | 75 | Interpolation in Python is: 76 | 77 | ```python 78 | first = "Don't worry," 79 | second = 'be happy' 80 | print('%s %s' % (first, second)) 81 | ``` 82 | 83 | Since 3.6 you can use: 84 | 85 | ```python 86 | first = "Don't worry," 87 | second = 'be happy' 88 | print(f'{first} {second}') 89 | ``` 90 | 91 | To achieve it: 92 | 93 | 1. Change `data/code.yml` 94 | ```yaml 95 | python: 96 | .: string_interpolation.py 97 | '3.6': string_interpolation.py 98 | ``` 99 | 2. Add the first example to `code/python/` 100 | 3. Add the second example to `code/python/3.6` 101 | 102 | ## Deploy 103 | 104 | ``` 105 | git checkout source 106 | bundle exec middleman build 107 | bundle exec middleman deploy 108 | ``` 109 | 110 | ## Contributing 111 | 112 | Feel free to add or modify any examples. 113 | 114 | 1. Fork it ( https://github.com/evmorov/lang-compare/fork ) 115 | 2. Create your feature branch (`git checkout -b my-new-feature`) 116 | 3. Commit your changes (`git commit -am 'Add some feature'`) 117 | 4. Push to the branch (`git push origin my-new-feature`) 118 | 5. Create a new Pull Request 119 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | activesupport (8.0.2) 5 | base64 6 | benchmark (>= 0.3) 7 | bigdecimal 8 | concurrent-ruby (~> 1.0, >= 1.3.1) 9 | connection_pool (>= 2.2.5) 10 | drb 11 | i18n (>= 1.6, < 2) 12 | logger (>= 1.4.2) 13 | minitest (>= 5.1) 14 | securerandom (>= 0.3) 15 | tzinfo (~> 2.0, >= 2.0.5) 16 | uri (>= 0.13.1) 17 | addressable (2.8.7) 18 | public_suffix (>= 2.0.2, < 7.0) 19 | ast (2.4.2) 20 | autoprefixer-rails (10.4.19.0) 21 | execjs (~> 2) 22 | base64 (0.2.0) 23 | benchmark (0.4.0) 24 | bigdecimal (3.1.9) 25 | bootstrap-sass (3.4.1) 26 | autoprefixer-rails (>= 5.2.1) 27 | sassc (>= 2.0.0) 28 | coffee-script (2.4.1) 29 | coffee-script-source 30 | execjs 31 | coffee-script-source (1.12.2) 32 | concurrent-ruby (1.3.5) 33 | connection_pool (2.5.0) 34 | contracts (0.17.2) 35 | date (3.4.1) 36 | dotenv (3.1.7) 37 | drb (2.2.1) 38 | erubi (1.13.1) 39 | execjs (2.10.0) 40 | fast_blank (1.0.1) 41 | fastimage (2.4.0) 42 | ffi (1.17.1) 43 | haml (6.3.0) 44 | temple (>= 0.8.2) 45 | thor 46 | tilt 47 | hamster (3.0.0) 48 | concurrent-ruby (~> 1.0) 49 | hashie (5.0.0) 50 | i18n (1.14.7) 51 | concurrent-ruby (~> 1.0) 52 | jquery-middleman (3.1.2) 53 | thor (>= 0.14, < 2.0) 54 | json (2.10.2) 55 | kramdown (2.5.1) 56 | rexml (>= 3.3.9) 57 | language_server-protocol (3.17.0.4) 58 | lint_roller (1.1.0) 59 | listen (3.9.0) 60 | rb-fsevent (~> 0.10, >= 0.10.3) 61 | rb-inotify (~> 0.9, >= 0.9.10) 62 | logger (1.6.6) 63 | memoist (0.16.2) 64 | middleman (4.6.0) 65 | middleman-cli (= 4.6.0) 66 | middleman-core (= 4.6.0) 67 | middleman-cli (4.6.0) 68 | thor (>= 0.17.0, < 1.3.0) 69 | middleman-core (4.6.0) 70 | activesupport (>= 6.1) 71 | addressable (~> 2.4) 72 | bundler (~> 2.0) 73 | coffee-script (~> 2.2) 74 | contracts 75 | dotenv 76 | erubi 77 | execjs (~> 2.0) 78 | fast_blank 79 | fastimage (~> 2.0) 80 | haml (>= 4.0.5) 81 | hamster (~> 3.0) 82 | hashie (>= 3.4, < 6.0) 83 | i18n (>= 1.6, < 1.15) 84 | kramdown (~> 2.4) 85 | listen (~> 3.0) 86 | memoist (~> 0.14) 87 | padrino-helpers (~> 0.15.0) 88 | parallel 89 | rack (>= 3) 90 | rackup 91 | sassc (~> 2.0) 92 | servolux 93 | tilt (~> 2.2) 94 | toml 95 | uglifier (>= 3, < 5) 96 | webrick 97 | middleman-deploy (2.0.0.pre.alpha) 98 | middleman-core (>= 3.2) 99 | net-sftp 100 | ptools 101 | middleman-sprockets (4.0.0) 102 | middleman-core (~> 4.0) 103 | sprockets (>= 3.0) 104 | middleman-syntax (3.4.0) 105 | middleman-core (>= 3.2) 106 | rouge (~> 3.2) 107 | minitest (5.25.5) 108 | net-ftp (0.3.8) 109 | net-protocol 110 | time 111 | net-protocol (0.2.2) 112 | timeout 113 | net-sftp (4.0.0) 114 | net-ssh (>= 5.0.0, < 8.0.0) 115 | net-ssh (7.3.0) 116 | padrino-helpers (0.15.3) 117 | i18n (>= 0.6.7, < 2) 118 | padrino-support (= 0.15.3) 119 | tilt (>= 1.4.1, < 3) 120 | padrino-support (0.15.3) 121 | parallel (1.26.3) 122 | parser (3.3.7.1) 123 | ast (~> 2.4.1) 124 | racc 125 | parslet (2.0.0) 126 | ptools (1.5.0) 127 | public_suffix (6.0.1) 128 | racc (1.8.1) 129 | rack (3.1.12) 130 | rackup (2.2.1) 131 | rack (>= 3) 132 | rainbow (3.1.1) 133 | rake (13.2.1) 134 | rb-fsevent (0.11.2) 135 | rb-inotify (0.11.1) 136 | ffi (~> 1.0) 137 | regexp_parser (2.10.0) 138 | rexml (3.4.1) 139 | rouge (3.30.0) 140 | rubocop (1.74.0) 141 | json (~> 2.3) 142 | language_server-protocol (~> 3.17.0.2) 143 | lint_roller (~> 1.1.0) 144 | parallel (~> 1.10) 145 | parser (>= 3.3.0.2) 146 | rainbow (>= 2.2.2, < 4.0) 147 | regexp_parser (>= 2.9.3, < 3.0) 148 | rubocop-ast (>= 1.38.0, < 2.0) 149 | ruby-progressbar (~> 1.7) 150 | unicode-display_width (>= 2.4.0, < 4.0) 151 | rubocop-ast (1.38.1) 152 | parser (>= 3.3.1.0) 153 | ruby-progressbar (1.13.0) 154 | sassc (2.4.0) 155 | ffi (~> 1.9) 156 | securerandom (0.4.1) 157 | servolux (0.13.0) 158 | sprockets (4.2.1) 159 | concurrent-ruby (~> 1.0) 160 | rack (>= 2.2.4, < 4) 161 | temple (0.10.3) 162 | thor (1.2.2) 163 | tilt (2.6.0) 164 | time (0.4.1) 165 | date 166 | timeout (0.4.3) 167 | toml (0.3.0) 168 | parslet (>= 1.8.0, < 3.0.0) 169 | tzinfo (2.0.6) 170 | concurrent-ruby (~> 1.0) 171 | uglifier (4.2.1) 172 | execjs (>= 0.3.0, < 3) 173 | unicode-display_width (3.1.4) 174 | unicode-emoji (~> 4.0, >= 4.0.4) 175 | unicode-emoji (4.0.4) 176 | uri (1.0.3) 177 | webrick (1.9.1) 178 | 179 | PLATFORMS 180 | ruby 181 | 182 | DEPENDENCIES 183 | bootstrap-sass (~> 3.3) 184 | jquery-middleman (~> 3.1) 185 | middleman (~> 4.1) 186 | middleman-deploy (~> 2.0.0.pre.alpha) 187 | middleman-sprockets (~> 4.0.0.rc) 188 | middleman-syntax 189 | net-ftp 190 | rake 191 | rubocop 192 | tzinfo-data 193 | wdm (~> 0.1) 194 | 195 | BUNDLED WITH 196 | 2.6.6 197 | -------------------------------------------------------------------------------- /data/code.yml: -------------------------------------------------------------------------------- 1 | String: 2 | Create: 3 | ruby: string_create.rb 4 | javascript: string-create.js 5 | java: StringCreate.java 6 | php: StringCreate.php 7 | python: string_create.py 8 | kotlin: StringCreate.kts 9 | Concatenation: 10 | ruby: string_concat.rb 11 | javascript: string-concat.js 12 | java: StringConcat.java 13 | php: StringConcat.php 14 | python: string_concat.py 15 | kotlin: StringConcat.kts 16 | Interpolation: 17 | ruby: string_interpolation.rb 18 | javascript: string-interpolation.js 19 | java: no.java 20 | php: string_interpolation.php 21 | python: 22 | .: string_interpolation.py 23 | '3.6': string_interpolation.py 24 | kotlin: StringInterpolation.kts 25 | Remove part: 26 | ruby: string_remove.rb 27 | javascript: string-remove.js 28 | java: StringRemove.java 29 | php: StringRemove.php 30 | python: string_remove.py 31 | kotlin: StringRemove.kts 32 | Replace: 33 | ruby: string_replace.rb 34 | javascript: string-replace.js 35 | java: StringReplace.java 36 | php: StringReplace.php 37 | python: string_replace.py 38 | kotlin: StringReplace.kts 39 | Split: 40 | ruby: string_split.rb 41 | javascript: string-split.js 42 | java: StringSplit.java 43 | php: StringSplit.php 44 | python: string_split.py 45 | kotlin: StringSplit.kts 46 | Remove leading and trailing whitespace: 47 | ruby: string_remove_whistespace.rb 48 | javascript: string-remove-whistespace.js 49 | java: StringRemoveWhitespace.java 50 | php: StringRemoveWhitespace.php 51 | python: string_remove_whistespace.py 52 | kotlin: StringRemoveWhitespace.kts 53 | Compare: 54 | ruby: string_compare.rb 55 | javascript: string-compare.js 56 | java: StringCompare.java 57 | php: StringCompare.php 58 | python: string_compare.py 59 | kotlin: StringCompare.kts 60 | Regex: 61 | ruby: string_regex.rb 62 | javascript: string-regex.js 63 | java: StringRegex.java 64 | php: StringRegex.php 65 | python: string_regex.py 66 | kotlin: StringRegex.kts 67 | Number: 68 | Increment: 69 | ruby: number_increment.rb 70 | javascript: number-increment.js 71 | java: NumberIncrement.java 72 | php: NumberIncrement.php 73 | python: number_increment.py 74 | kotlin: NumberIncrement.kts 75 | Compare: 76 | ruby: number_compare.rb 77 | javascript: number-compare.js 78 | java: NumberCompare.java 79 | php: NumberCompare.php 80 | python: number_compare.py 81 | kotlin: NumberCompare.kts 82 | Random: 83 | ruby: number_random.rb 84 | javascript: number-random.js 85 | java: NumberRandom.java 86 | php: NumberRandom.php 87 | python: number_random.py 88 | kotlin: NumberRandom.kts 89 | Float: 90 | ruby: number_float.rb 91 | javascript: number-float.js 92 | java: NumberFloat.java 93 | php: NumberFloat.php 94 | python: number_float.py 95 | kotlin: NumberFloat.kts 96 | Type: 97 | Get type of object: 98 | ruby: type_get_type.rb 99 | javascript: type-get-type.js 100 | java: TypeGetType.java 101 | php: TypeGetType.php 102 | python: type_get_type.py 103 | kotlin: TypeGetType.kts 104 | Int to Float: 105 | ruby: type_int_to_float.rb 106 | javascript: type-int-to-float.js 107 | java: TypeIntToFloat.java 108 | php: TypeIntToFloat.php 109 | python: type_int_to_float.py 110 | kotlin: TypeIntToFloat.kts 111 | Int to String: 112 | ruby: type_int_to_string.rb 113 | javascript: type-int-to-string.js 114 | java: TypeIntToString.java 115 | php: TypeIntToString.php 116 | python: type_int_to_string.py 117 | kotlin: TypeIntToString.kts 118 | String to Int: 119 | ruby: type_string_to_int.rb 120 | javascript: type-string-to-int.js 121 | java: TypeStringToInt.java 122 | php: TypeStringToInt.php 123 | python: type_string_to_int.py 124 | kotlin: TypeStringToInt.kts 125 | String?: 126 | ruby: type_is_string.rb 127 | javascript: type-is-string.js 128 | java: TypeIsString.java 129 | php: TypeIsString.php 130 | python: type_is_string.py 131 | kotlin: TypeIsString.kts 132 | Null/True/False?: 133 | ruby: type_null_true_false.rb 134 | javascript: type-null-true-false.js 135 | java: TypeNullTrueFalse.java 136 | php: TypeNullTrueFalse.php 137 | python: type_null_true_false.py 138 | kotlin: TypeNullTrueFalse.kts 139 | Array: 140 | Create populated: 141 | ruby: array_create_populated.rb 142 | javascript: array-create-populated.js 143 | java: ArrayCreatePopulated.java 144 | php: ArrayCreatePopulated.php 145 | python: array_create_populated.py 146 | kotlin: ArrayCreatePopulated.kts 147 | Add: 148 | ruby: array_add.rb 149 | javascript: array-add.js 150 | java: ArrayAdd.java 151 | php: ArrayAdd.php 152 | python: array_add.py 153 | kotlin: ArrayAdd.kts 154 | With different types: 155 | ruby: array_with_different_types.rb 156 | javascript: array-with-different-types.js 157 | java: ArrayDifferentTypes.java 158 | php: ArrayDifferentTypes.php 159 | python: array_with_different_types.py 160 | kotlin: ArrayWithDifferentTypes.kts 161 | Include?: 162 | ruby: array_is_include.rb 163 | javascript: array-is-include.js 164 | java: ArrayIsInclude.java 165 | php: ArrayIsInclude.php 166 | python: array_is_include.py 167 | kotlin: ArrayIsInclude.kts 168 | Iterate: 169 | ruby: array_iterate.rb 170 | javascript: array-iterate.js 171 | java: ArrayIterate.java 172 | php: ArrayIterate.php 173 | python: array_iterate.py 174 | kotlin: ArrayIterate.kts 175 | Iterate with index: 176 | ruby: array_iterate_with_index.rb 177 | javascript: array-iterate-with-index.js 178 | java: ArrayIterateWithIndex.java 179 | php: ArrayIterateWithIndex.php 180 | python: array_iterate_with_index.py 181 | kotlin: ArrayIterateWithIndex.kts 182 | Get first, last element: 183 | ruby: array_get_first_and_last.rb 184 | javascript: array-get-first-and-last.js 185 | java: ArrayGetFirstAndLast.java 186 | php: ArrayGetFirstAndLast.php 187 | python: array_get_first_and_last.py 188 | kotlin: ArrayGetFirstAndLast.kts 189 | Find first: 190 | ruby: array_find.rb 191 | javascript: array-find.js 192 | java: ArrayFind.java 193 | php: ArrayFind.php 194 | python: array_find.py 195 | kotlin: ArrayFind.kts 196 | Select (find all): 197 | ruby: array_select.rb 198 | javascript: array-select.js 199 | java: ArraySelect.java 200 | php: ArraySelect.php 201 | python: array_select.py 202 | kotlin: ArraySelect.kts 203 | Map (change all): 204 | ruby: array_map.rb 205 | javascript: array-map.js 206 | java: ArrayMap.java 207 | php: ArrayMap.php 208 | python: array_map.py 209 | kotlin: ArrayMap.kts 210 | Concatenation: 211 | ruby: array_concat.rb 212 | javascript: array-concat.js 213 | java: ArrayConcat.java 214 | php: ArrayConcat.php 215 | python: array_concat.py 216 | kotlin: ArrayConcat.kts 217 | Sort: 218 | ruby: array_sort.rb 219 | javascript: array-sort.js 220 | java: ArraySort.java 221 | php: ArraySort.php 222 | python: array_sort.py 223 | kotlin: ArraySort.kts 224 | Multidimensional: 225 | ruby: array_multi.rb 226 | javascript: array-multi.js 227 | java: ArrayMulti.java 228 | php: ArrayMulti.php 229 | python: array_multi.py 230 | kotlin: ArrayMulti.kts 231 | Size: 232 | ruby: array_size.rb 233 | javascript: array-size.js 234 | java: ArraySize.java 235 | php: ArraySize.php 236 | python: array_size.py 237 | kotlin: ArraySize.kts 238 | Count: 239 | ruby: array_count.rb 240 | javascript: array-count.js 241 | java: ArrayCount.java 242 | php: ArrayCount.php 243 | python: array_count.py 244 | kotlin: ArrayCount.kts 245 | Reduce: 246 | ruby: array_reduce.rb 247 | javascript: array-reduce.js 248 | java: ArrayReduce.java 249 | php: ArrayReduce.php 250 | python: array_reduce.py 251 | kotlin: ArrayReduce.kts 252 | Index of element: 253 | ruby: array_index_of_element.rb 254 | javascript: array-index-of-element.js 255 | java: ArrayIndexOfElement.java 256 | php: ArrayIndexOfElement.php 257 | python: array_index_of_element.py 258 | kotlin: ArrayIndexOfElement.kts 259 | Delete element: 260 | ruby: array_delete_element.rb 261 | javascript: array-delete-element.js 262 | java: ArrayDeleteElement.java 263 | php: ArrayDeleteElement.php 264 | python: array_delete_element.py 265 | kotlin: ArrayDeleteElement.kts 266 | Unique: 267 | ruby: array_unique.rb 268 | javascript: array-unique.js 269 | java: ArrayUnique.java 270 | php: ArrayUnique.php 271 | python: array_unique.py 272 | kotlin: ArrayUnique.kts 273 | Hash (map): 274 | Create populated: 275 | ruby: hash_create_populated.rb 276 | javascript: hash-create-populated.js 277 | java: HashCreatePopulated.java 278 | php: HashCreatePopulated.php 279 | python: hash_create_populated.py 280 | kotlin: HashCreatePopulated.kts 281 | Add: 282 | ruby: hash_add.rb 283 | javascript: hash-add.js 284 | java: HashAdd.java 285 | php: HashAdd.php 286 | python: hash_add.py 287 | kotlin: HashAdd.kts 288 | Iterate: 289 | ruby: hash_iterate.rb 290 | javascript: hash-iterate.js 291 | java: HashIterate.java 292 | php: HashIterate.php 293 | python: hash_iterate.py 294 | kotlin: HashIterate.kts 295 | Include?: 296 | ruby: hash_is_include.rb 297 | javascript: hash-is-include.js 298 | java: HashIsInclude.java 299 | php: HashIsInclude.php 300 | python: hash_is_include.py 301 | kotlin: HashIsInclude.kts 302 | Get value: 303 | ruby: hash_get_value.rb 304 | javascript: hash-get-value.js 305 | java: HashGetValue.java 306 | php: HashGetValue.php 307 | python: hash_get_value.py 308 | kotlin: HashGetValue.kts 309 | Size: 310 | ruby: hash_size.rb 311 | javascript: hash-size.js 312 | java: HashSize.java 313 | php: HashSize.php 314 | python: hash_size.py 315 | kotlin: HashSize.kts 316 | Other structure: 317 | Boolean: 318 | ruby: other_structure_boolean.rb 319 | javascript: other-structure-boolean.js 320 | java: OtherStructureBoolean.java 321 | php: OtherStructureBoolean.php 322 | python: other_structure_boolean.py 323 | kotlin: OtherStructureBoolean.kts 324 | Constant: 325 | ruby: other_structure_constant.rb 326 | javascript: other-structure-constant.js 327 | java: OtherStructureConstant.java 328 | php: OtherStructureConstant.php 329 | python: other_structure_constant.py 330 | kotlin: OtherStructureConstant.kts 331 | Constant list: 332 | ruby: other_structure_constant_list.rb 333 | javascript: other-structure-constant-list.js 334 | java: OtherStructureConstantList.java 335 | php: OtherStructureConstantList.php 336 | python: other_structure_constant_list.py 337 | kotlin: OtherStructureConstantList.kts 338 | Struct: 339 | ruby: other_structure_struct.rb 340 | javascript: no.js 341 | java: no.java 342 | php: no.php 343 | python: other_structure_struct.py 344 | kotlin: OtherStructureStruct.kts 345 | Conditional: 346 | If: 347 | ruby: conditional_if.rb 348 | javascript: conditional-if.js 349 | java: ConditionalIf.java 350 | php: ConditionalIf.php 351 | python: conditional_if.py 352 | kotlin: ConditionalIf.kts 353 | Unless: 354 | ruby: conditional_unless.rb 355 | javascript: conditional-unless.js 356 | java: ConditionalUnless.java 357 | php: ConditionalUnless.php 358 | python: conditional_unless.py 359 | kotlin: ConditionalUnless.kts 360 | If/else: 361 | ruby: conditional_if_else.rb 362 | javascript: conditional-if-else.js 363 | java: ConditionalIfElse.java 364 | php: ConditionalIfElse.php 365 | python: conditional_if_else.py 366 | kotlin: ConditionalIfElse.kts 367 | And/Or: 368 | ruby: conditional_and_or.rb 369 | javascript: conditional-and-or.js 370 | java: ConditionalAndOr.java 371 | php: ConditionalAndOr.php 372 | python: conditional_and_or.py 373 | kotlin: ConditionalAndOr.kts 374 | Switch: 375 | ruby: conditional_switch.rb 376 | javascript: conditional-switch.js 377 | java: ConditionalSwitch.java 378 | php: ConditionalSwitch.php 379 | python: conditional_switch.py 380 | kotlin: ConditionalSwitch.kts 381 | Switch as else if: 382 | ruby: conditional_switch_as_else_if.rb 383 | javascript: no.js 384 | java: no.java 385 | php: no.php 386 | python: conditional_switch_as_else_if.py 387 | kotlin: ConditionalSwitch.kts 388 | Ternary: 389 | ruby: conditional_ternary.rb 390 | javascript: conditional-ternary.js 391 | java: ConditionalTernary.java 392 | php: ConditionalTernary.php 393 | python: conditional_ternary.py 394 | kotlin: ConditionalTernary.kts 395 | If assign: 396 | ruby: conditional_if_assign.rb 397 | javascript: conditional-if-assign.js 398 | java: no.java 399 | php: no.php 400 | python: conditional_if_assign.py 401 | kotlin: ConditionalIfAssign.kts 402 | Loop: 403 | For: 404 | ruby: loop_for.rb 405 | javascript: loop-for.js 406 | java: LoopFor.java 407 | php: LoopFor.php 408 | python: loop_for.py 409 | kotlin: LoopFor.kts 410 | For with a step: 411 | ruby: loop_for_with_step.rb 412 | javascript: loop-for-with-step.js 413 | java: LoopForWithStep.java 414 | php: LoopForWithStep.php 415 | python: loop_for_with_step.py 416 | kotlin: LoopForWithStep.kts 417 | Times: 418 | ruby: loop_times.rb 419 | javascript: loop-times.js 420 | java: LoopTimes.java 421 | php: LoopTimes.php 422 | python: loop_times.py 423 | kotlin: LoopTimes.kts 424 | While: 425 | ruby: loop_while.rb 426 | javascript: loop-while.js 427 | java: LoopWhile.java 428 | php: LoopWhile.php 429 | python: loop_while.py 430 | kotlin: LoopWhile.kts 431 | Until: 432 | ruby: loop_until.rb 433 | javascript: loop-until.js 434 | java: LoopUntil.java 435 | php: LoopUntil.php 436 | python: loop_until.py 437 | kotlin: LoopUntil.kts 438 | Return array: 439 | ruby: loop_return_array.rb 440 | javascript: loop-return-array.js 441 | java: no.java 442 | php: no.php 443 | python: loop_return_array.py 444 | kotlin: LoopReturnArray.kts 445 | Break: 446 | ruby: loop_break.rb 447 | javascript: loop-break.js 448 | java: LoopBreak.java 449 | php: LoopBreak.php 450 | python: loop_break.py 451 | kotlin: LoopBreak.kts 452 | Next/Continue: 453 | ruby: loop_next.rb 454 | javascript: loop-next.js 455 | java: LoopNext.java 456 | php: LoopNext.php 457 | python: loop_next.py 458 | kotlin: LoopNext.kts 459 | Math: 460 | Max/Min: 461 | ruby: math_max_min.rb 462 | javascript: math-max-min.js 463 | java: MathMaxMin.java 464 | php: MathMaxMin.php 465 | python: math_max_min.py 466 | kotlin: MathMaxMin.kts 467 | Sqrt: 468 | ruby: math_sqrt.rb 469 | javascript: math-sqrt.js 470 | java: MathSqrt.java 471 | php: MathSqrt.php 472 | python: math_sqrt.py 473 | kotlin: MathSqrt.kts 474 | Error handling: 475 | Try/catch/finally: 476 | ruby: error_try_catch.rb 477 | javascript: error-try-catch.js 478 | java: ErrorTryCatch.java 479 | php: ErrorTryCatch.php 480 | python: error_try_catch.py 481 | kotlin: ErrorTryCatch.kts 482 | With a message: 483 | ruby: error_with_a_message.rb 484 | javascript: error-with-a-message.js 485 | java: ErrorWithAMessage.java 486 | php: ErrorWithAMessage.php 487 | python: error_with_a_message.py 488 | kotlin: ErrorWithAMessage.kts 489 | Method: 490 | ruby: error_method.rb 491 | javascript: no.js 492 | java: no.java 493 | php: no.php 494 | python: error_method.py 495 | kotlin: ErrorMethod.kts 496 | Throw exception: 497 | ruby: error_throw.rb 498 | javascript: error-throw.js 499 | java: ErrorThrow.java 500 | php: ErrorThrow.php 501 | python: error_throw.py 502 | kotlin: ErrorThrow.kts 503 | File: 504 | Read: 505 | ruby: file_read.rb 506 | javascript: file-read.js 507 | java: FileRead.java 508 | php: FileRead.php 509 | python: file_read.py 510 | kotlin: FileRead.kts 511 | Write: 512 | ruby: file_write.rb 513 | javascript: file-write.js 514 | java: FileWrite.java 515 | php: FileWrite.php 516 | python: file_write.py 517 | kotlin: FileWrite.kts 518 | Get working dir path: 519 | ruby: file_get_working_dir.rb 520 | javascript: file-get-working-dir.js 521 | java: FileGetWorkingDir.java 522 | php: FileGetWorkingDir.php 523 | python: file_get_working_dir.py 524 | kotlin: FileGetWorkingDir.kts 525 | File path: 526 | ruby: file_path.rb 527 | javascript: file-path.js 528 | java: FilePath.java 529 | php: FilePath.php 530 | python: file_path.py 531 | kotlin: FilePath.kts 532 | Dir path: 533 | ruby: file_dir_path.rb 534 | javascript: file-dir-path.js 535 | java: FileDirPath.java 536 | php: FileDirPath.php 537 | python: file_dir_path.py 538 | kotlin: FileDirPath.kts 539 | Parent dir path: 540 | ruby: file_parent_dir_path.rb 541 | javascript: file-parent-dir-path.js 542 | java: FileParentDirPath.java 543 | php: FileParentDirPath.php 544 | python: file_parent_dir_path.py 545 | kotlin: FileParentDirPath.kts 546 | Sister dir path: 547 | ruby: file_sister_dir_path.rb 548 | javascript: file-sister-dir-path.js 549 | java: FileSisterDirPath.java 550 | php: FileSisterDirPath.php 551 | python: file_sister_dir_path.py 552 | kotlin: FileSisterDirPath.kts 553 | Method: 554 | Declare: 555 | ruby: method_declare.rb 556 | javascript: method-declare.js 557 | java: MethodDeclare.java 558 | php: MethodDeclare.php 559 | python: method_declare.py 560 | kotlin: MethodDeclare.kts 561 | Multiple arguments: 562 | ruby: method_multi_arg.rb 563 | javascript: method-multi-arg.js 564 | java: MethodMultiArg.java 565 | php: MethodMultiArg.php 566 | python: method_multi_arg.py 567 | kotlin: MethodMultiArg.kts 568 | Default value for argument: 569 | ruby: method_default_value.rb 570 | javascript: method-default-value.js 571 | java: no.java 572 | php: no.php 573 | python: method_default_value.py 574 | kotlin: MethodDefaultValue.kts 575 | Return: 576 | ruby: method_return.rb 577 | javascript: method-return.js 578 | java: MethodReturn.java 579 | php: MethodReturn.php 580 | python: method_return.py 581 | kotlin: MethodReturn.kts 582 | Closure: 583 | ruby: method_closure.rb 584 | javascript: method-closure.js 585 | java: no.java 586 | php: no.php 587 | python: method_closure.py 588 | kotlin: MethodClosure.kts 589 | Block passing: 590 | ruby: method_block_passing.rb 591 | javascript: method-block-passing.js 592 | java: no.java 593 | php: no.php 594 | python: method_block_passing.py 595 | kotlin: MethodBlockPassing.kts 596 | Block binding: 597 | ruby: method_block_binding.rb 598 | javascript: method-block-binding.js 599 | java: no.java 600 | php: no.php 601 | python: method_block_binding.py 602 | kotlin: MethodBlockBinding.kts 603 | Initialize in runtime: 604 | ruby: method_init_in_runtime.rb 605 | javascript: no.js 606 | java: no.java 607 | php: no.php 608 | python: method_init_in_runtime.py 609 | kotlin: no.kts 610 | Alias: 611 | ruby: method_alias.rb 612 | javascript: method-alias.js 613 | java: no.java 614 | php: no.php 615 | python: method_alias.py 616 | kotlin: MethodAlias.kts 617 | Class: 618 | Declare: 619 | ruby: class_declare.rb 620 | javascript: class-declare.js 621 | java: ClassDeclare.java 622 | php: ClassDeclare.php 623 | python: class_declare.py 624 | kotlin: ClassDeclare.kts 625 | Constructor: 626 | ruby: class_constructor.rb 627 | javascript: class-constructor.js 628 | java: ClassConstructor.java 629 | php: ClassConstructor.php 630 | python: class_constructor.py 631 | kotlin: ClassConstructor.kts 632 | Method call: 633 | ruby: class_method_call.rb 634 | javascript: class-method-call.js 635 | java: ClassMethodCall.java 636 | php: ClassMethodCall.php 637 | python: class_method_call.py 638 | kotlin: ClassMethodCall.kts 639 | Class method: 640 | ruby: class_class_method.rb 641 | javascript: class-class-method.js 642 | java: ClassClassMethod.java 643 | php: ClassClassMethod.php 644 | python: class_class_method.py 645 | kotlin: ClassClassMethod.kts 646 | Private method: 647 | ruby: class_private_method.rb 648 | javascript: no.js 649 | java: ClassPrivateMethod.java 650 | php: ClassPrivateMethod.php 651 | python: class_private_method.py 652 | kotlin: ClassPrivateMethod.kts 653 | Private method, access instance variable: 654 | ruby: class_private_method_access_instance_var.rb 655 | javascript: no.js 656 | java: ClassPrivateMethodAccessInstance.java 657 | php: ClassPrivateMethodAccessInstance.php 658 | python: class_private_method_access_instance_var.py 659 | kotlin: ClassPrivateMethodAccessInstance.kts 660 | Field: 661 | ruby: class_field.rb 662 | javascript: class-field.js 663 | java: ClassField.java 664 | php: ClassField.php 665 | python: class_field.py 666 | kotlin: ClassField.kts 667 | Get/set: 668 | ruby: class_get_set.rb 669 | javascript: class-get-set.js 670 | java: ClassGetSet.java 671 | php: ClassGetSet.php 672 | python: class_get_set.py 673 | kotlin: ClassGetSet.kts 674 | Inheritance: 675 | ruby: class_inheritance.rb 676 | javascript: class-inheritance.js 677 | java: ClassInheritance.java 678 | php: ClassInheritance.php 679 | python: class_inheritance.py 680 | kotlin: ClassInheritance.kts 681 | Mixin: 682 | ruby: class_mixin.rb 683 | javascript: no.js 684 | java: no.java 685 | php: no.php 686 | python: class_mixin.py 687 | kotlin: ClassMixin.kts 688 | Has method?: 689 | ruby: class_has_method.rb 690 | javascript: class-has-method.js 691 | java: ClassHasMethod.java 692 | php: ClassHasMethod.php 693 | python: class_has_method.py 694 | kotlin: ClassHasMethod.kts 695 | Other: 696 | Comment: 697 | ruby: other_comment.rb 698 | javascript: other-comment.js 699 | java: OtherComment.java 700 | php: OtherComment.php 701 | python: other_comment.py 702 | kotlin: OtherComment.kts 703 | Assign value if not exist: 704 | ruby: other_assign_value_if_not_exist.rb 705 | javascript: no.js 706 | java: no.java 707 | php: no.php 708 | python: other_assign_value_if_not_exist.py 709 | kotlin: OtherAssignValueIfNotExist.kts 710 | Safe navigation: 711 | ruby: other_safe_navigation.rb 712 | javascript: no.js 713 | java: no.java 714 | php: no.php 715 | python: no.py 716 | kotlin: OtherSafeNavigation.kts 717 | Import another file: 718 | ruby: other_import_file.rb 719 | javascript: other-import-file.js 720 | java: OtherImportFile.java 721 | php: OtherImportFile.php 722 | python: other_import_file.py 723 | kotlin: OtherImportFile.kts 724 | Destructuring assignment: 725 | ruby: other_destructing_assignment.rb 726 | javascript: other-destructing-assignment.js 727 | java: no.java 728 | php: no.php 729 | python: other_destructing_assignment.py 730 | kotlin: OtherDestructingAssignment.kts 731 | Date: 732 | ruby: other_date.rb 733 | javascript: other-date.js 734 | java: OtherDate.java 735 | php: OtherDate.php 736 | python: other_date.py 737 | kotlin: OtherDate.kts 738 | Time: 739 | ruby: other_time.rb 740 | javascript: other-time.js 741 | java: OtherTime.java 742 | php: OtherTime.php 743 | python: other_time.py 744 | kotlin: OtherTime.kts 745 | Not: 746 | ruby: other_not.rb 747 | javascript: other-not.js 748 | java: OtherNot.java 749 | php: OtherNot.php 750 | python: other_not.py 751 | kotlin: OtherNot.kts 752 | Assign this or that: 753 | ruby: conditional_assign_this_or_that.rb 754 | javascript: no.js 755 | java: no.java 756 | php: no.php 757 | python: conditional_assign_this_or_that.py 758 | kotlin: ConditionalAssignThisOrThat.kts 759 | Run command: 760 | ruby: other_run_command.rb 761 | javascript: other-run-command.js 762 | java: OtherRunCommand.java 763 | php: OtherRunCommand.php 764 | python: other_run_command.py 765 | kotlin: OtherRunCommand.kts 766 | --------------------------------------------------------------------------------