Skip to content

Instantly share code, notes, and snippets.

View susu's full-sized avatar

Marton Suranyi susu

View GitHub Profile
@susu
susu / damagesystem.rs
Created May 1, 2020 09:31
example for damaging tile
struct StaticDamageSystem;
impl<'s> System<'s> for StaticDamageSystem {
type SystemData = (
WriteStorage<'s, Health>,
ReadStorage<'s, StaticDamage>,
ReadStorage<'s, TilePosition>,
);
fn run(&mut self, (mut healths, damages, positions): Self::SystemData) {
@susu
susu / cout.scala
Created June 28, 2018 08:35
C++ like printing in scala.
object endl {}
object cout {
def <<(e: endl.type) = {
print("\n")
this
}
def <<(s: String) = {
print(s)
this
}
// will it compile with "SCALA_OPTS=-Xfatal-warnings"?
sealed trait ADT
final case class Apple(id: Int) extends ADT
final case class Banana(id: String) extends ADT
final case class Pear(id: Boolean) extends ADT
object Obj {
def fun(x: ADT): String = {
fn bar(y: ~int) {}
fn foo() {
let x = box 75;
if ...
{
bar(x);
}
}
@susu
susu / coutstub.cpp
Last active December 16, 2015 13:48
// 3rd party library source
// g++ -fPIC -shared coutstub.cpp -o libcoutstub.so
#include <iostream>
#include "coutstub.hpp"
void print()
{
@susu
susu / autoptr_problem.cpp
Created March 18, 2013 13:18
Why auto_ptr is a problem? Even if it is used as a RAII object, can lead to problems. (Furthermore it is deprecated in c++11.) (boost::scoped_ptr has no such problems (c++03) or use std::unique_ptr (c++11) ).
#include <iostream>
#include <memory>
class A
{
public:
A()
: m_int(new int(10))
{}
@susu
susu / second.rb
Created November 8, 2012 16:36
jenkins-json-api-ruby
require 'json'
require 'open-uri'
host = ARGV[0]
raise "Missing argument: host" if host.nil?
jenkins_root = JSON.parse(open("http://#{host}/api/json").read)