Skip to content

Instantly share code, notes, and snippets.

View marciok's full-sized avatar
🎯
Focusing

Marcio Klepacz marciok

🎯
Focusing
View GitHub Profile
@marciok
marciok / Frienship-0.js
Last active August 1, 2017 13:18
Token example
pragma solidity ^0.4.11
contract Friendship {
}
// 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"
@marciok
marciok / type-inf.swift
Created November 28, 2016 19:12
Is that a bug? 🤔
// 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
//
// A Tic-Tac-Toe game written in Swift using a functional programming approach.
//
//
// Created by Marcio Klepacz on 8/10/16.
//
//
import Foundation
@marciok
marciok / dijkstra.swift
Created June 22, 2016 21:15
Dijkstra's algorithm in Swift 3
/**
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
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}"
let gravity = 9.8
public func calculateWeight(mass: Double) -> Double {
return mass * gravity
}
def hello name
"Hello #{name} from Ruby!"
end
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))
import PackageDescription
let package = Package(
name: "example",
dependencies: [
.Package(url: "https://github.com/marciok/CRuby", majorVersion: 1)
]
)