This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.11 | |
| contract Friendship { | |
| mapping (address => uint256) public balanceOf;// This creates an array with all balances | |
| string public name; | |
| string public symbol; | |
| uint8 public decimals; | |
| /* Initializes contract with initial supply tokens to the creator of the contract */ | |
| function Friendship( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.11 | |
| contract Friendship { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright 2015 the V8 project authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include "include/libplatform/libplatform.h" | |
| #include "include/v8.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // It seems like Swift cannot correctly infer the type on the *second element* of the expression | |
| func postOrder(_ node: Node?) -> [Int] { | |
| guard let node = node else { return [] } | |
| return [node.content] + postOrder(node.left) + postOrder(node.right) // ❌ ERROR: 'Int' is not convertible to [Int] | |
| } | |
| // If I specify than it works... | |
| func postOrder(_ node: Node?) -> [Int] { | |
| guard let node = node else { return [] } | |
| return [node.content] + postOrder(node.left) + (postOrder(node.right) as [Int]) // ✅ That works |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // A Tic-Tac-Toe game written in Swift using a functional programming approach. | |
| // | |
| // | |
| // Created by Marcio Klepacz on 8/10/16. | |
| // | |
| // | |
| import Foundation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| Dijkstra's algorithm in Swift 3 | |
| The idea is to create a more protocol oriented implementation. | |
| Note: It could use some optimizations, if you wish to use in production. | |
| */ | |
| import Foundation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fiddle/import' | |
| module PonyScale | |
| extend Fiddle::Importer | |
| dlload '.build/release/libPonyScale.dylib' # dylib generated by SPM | |
| extern 'double _TF9PonyScale15calculateWeightFT4massSd_Sd(double)' # `calculateWeight(_:)` mangled name | |
| end | |
| weight = PonyScale::_TF9PonyScale15calculateWeightFT4massSd_Sd(18) # Calculating weight by passing 18 as mass | |
| puts "Your pony weighs: #{weight}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let gravity = 9.8 | |
| public func calculateWeight(mass: Double) -> Double { | |
| return mass * gravity | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def hello name | |
| "Hello #{name} from Ruby!" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import CRuby | |
| ruby_setup() | |
| rb_require("./hello_world/hello.rb") // Importing Ruby file | |
| var stringArg = rb_str_new_cstr("Swift") // Creating new Ruby string | |
| var result = rb_funcallv(0, rb_intern("hello"), 1, &(stringArg)) // Calling the function `hello` passing `stringArg` | |
| var str = rb_string_value_cstr(&(result)) // Extracting the returned value as C string | |
| print(String(cString: str)) |