Skip to content

Instantly share code, notes, and snippets.

View ranisalt's full-sized avatar

Ranieri Althoff ranisalt

View GitHub Profile
@ranisalt
ranisalt / cast.h
Created April 11, 2016 18:54
lexical cast in C++11
/* fallback */
template<class T>
T lexical_cast(const char* str)
{
static std::istringstream ss; /* reusing has severe (positive) impact on performance */
T value;
ss.str(str);
ss >> value;
ss.clear();
return value;
{
"targets": [
{
"target_name": "promises",
"sources": ["promises.cpp"],
"include_dirs": ["<!(node -e \"require('nan')\")"]
}
]
}
#!/usr/bin/bash
# usage: sh convert_sprites.sh <list of sprite dirs>
for dir in $@; do
convert \
\( $(find $dir ! -name '*_template.png' -type f | sort) -append \) \
\( $(find $dir -name '*_template.png' -type f | sort) -append \) \
-background none +append $(basename $dir).png
shift
done
@ranisalt
ranisalt / sum.cpp
Created September 26, 2015 22:10
C++ variadic sum
#include <iostream>
template<typename T>
int sum(T v) {
return v;
}
template<typename T, typename... Types>
int sum(T v, Types&&... others) {
return v + sum(others...);
@ranisalt
ranisalt / sieve.cpp
Created September 23, 2015 20:44
Sieve
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <limits>
#include <vector>
int main(int argc, char** argv) {
auto n = 100000U;
auto sieve = std::vector<uint32_t>(n);
@ranisalt
ranisalt / enable-passive-monsters.patch
Last active September 11, 2017 20:56
Passive monsters
From 8e70099afb04023b40f1ac4c4ac999cc22d11def Mon Sep 17 00:00:00 2001
From: Ranieri Althoff <[email protected]>
Date: Mon, 20 Jul 2015 03:15:34 -0300
Subject: [PATCH] Enable monster passive behavior
---
src/luascript.cpp | 13 +++++++++++++
src/luascript.h | 1 +
src/monster.cpp | 4 ++++
src/monster.h | 3 +++
@ranisalt
ranisalt / taming.lua
Last active August 29, 2015 14:25
vipmount.lua
local TYPE_ITEM, TYPE_MONSTER, TYPE_NPC = 0, 2, 3
local config = {
[5907] = {
name = 'bear',
id = 3,
type = TYPE_MONSTER,
chance = 20,
fail = {
{run = true, text = 'The bear ran away.'},
@ranisalt
ranisalt / fish.lua
Created July 16, 2015 20:27
fish.lua
local ITEM_MAGIC_WORM = 10224
local config = {
peixes = {
leveis = { 20, 40, 50, 60, 80, 100, 120 },
fish = {
[20] = 2670, -- 4
[40] = 2667, -- 8
[60] = 7159, -- 16
[80] = 7158, -- 20
@ranisalt
ranisalt / move-bug-report-to-lua.patch
Last active August 29, 2015 14:25
Move bug report to Lua
From d71d1eaa007b6f6d552eb7566572ce52f6ad1bc8 Mon Sep 17 00:00:00 2001
From: Ranieri Althoff <[email protected]>
Date: Wed, 15 Jul 2015 15:41:11 -0300
Subject: [PATCH] Move bug report to Lua
---
data/creaturescripts/creaturescripts.xml | 1 +
data/creaturescripts/scripts/report.lua | 26 +++++++++++++++++++++
src/creatureevent.cpp | 40 ++++++++++++++++++++++++++++++++
src/creatureevent.h | 3 +++
@ranisalt
ranisalt / fft.cpp
Last active August 29, 2015 14:23
Broken code
#include <cstdint>
#include <iostream>
#include <iomanip>
#include "fft.h"
FFT::FFT(const std::string& filename)
: file(filename, std::ifstream::binary)
{
int32_t chunk_id;
file.read(reinterpret_cast<char*>(&chunk_id), 4);