Skip to content

Instantly share code, notes, and snippets.

@agasiev
agasiev / gist:3862007
Created October 9, 2012 23:00
UI scale subsystem
#import "Settings.h"
@interface MainMenuScreen : MenuScreen {
@private
/*
Usage in code:
drButton * button = ...;
button.position = ui.menuButtons;
*/
class MainMenuUI {
@agasiev
agasiev / gist:3875736
Created October 11, 2012 21:50
libGdx atlas crop tool.
#import <Foundation/Foundation.h>
#import <iostream>
#import <string>
#import <list>
#import <fstream>
#import <tr1/unordered_map>
#import <Cocoa/Cocoa.h>
#import <AppKit/AppKit.h>
#import <vector>
@agasiev
agasiev / Viewport.h
Created October 17, 2012 22:59 — forked from anonymous/Viewport.h
cocos2d Viewport class which provides clipping for all nodes added to the Viewport
//
// Viewport.h
//
// Created by Benjamin Broll on 21.01.10.
// Copyright 2010 NEXT Munich. All rights reserved.
//
#import "cocos2d.h"
@agasiev
agasiev / brainfuck.cpp
Created November 10, 2012 04:09
Simple brainfuck interpreter
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
int main(int, char **) {
const size_t memory_buffer_size = 30000;
unsigned char memory[memory_buffer_size];
@agasiev
agasiev / SingleLinkedList.cpp
Created November 26, 2012 19:39
Single linked list reversion
using namespace std;
struct node {
node * next;
int value;
};
int main()
{
node * root = new node;
@agasiev
agasiev / RomipLoad.cpp
Last active October 13, 2015 08:08
Romip data fast loading for convert
// Compile:
// sudo g++ ./RomipLoad.cpp ./pugixml.cpp
#include "pugixml.hpp"
using namespace std;
struct imhonet {
string score;
string content_id;
string element_id;
@agasiev
agasiev / str64bit_hash.cpp
Created December 1, 2012 12:30
Simple 64 bit string hash
uint64_t str_hash1(std::string str) {
uint64_t result = 0;
uint64_t base = 53;
uint64_t base_pow = 1;
for_each(str.begin(), str.end(), [&](char c) {
result += (c - 'a' + 1) * base_pow; base_pow *= base;
});
return result;
}
@agasiev
agasiev / RabinKarp.cpp
Created December 2, 2012 19:06
Rabin-Karp algorithm
int main()
{
std::string str;
std::string substr;
cin >> str;
cin >> substr;
if (str.length() < substr.length()) {
return 0;
@agasiev
agasiev / trivial_prefix.cpp
Created December 3, 2012 23:51
Trivial implementation of prefix function
std::vector<unsigned> trivial_prefix_function(std::vector<unsigned> & prefix, std::string s) {
prefix.resize(s.length());
for (int i = 0; i < s.length(); ++i)
for (int j = 0; j <= i; ++j)
if (s.substr(0, j) == s.substr(i - j + 1, j))
prefix[i] = j;
return prefix;
}
@agasiev
agasiev / KMP_prefix.cpp
Created December 6, 2012 23:24
KMP prefix function
std::vector<unsigned> kmp_prefix_function(std::string s) {
size_t n = s.size();
std::vector<unsigned> result(n);
for (int i = 1; i < n; i++) {
int j = result[i-1];
while (j > 0 && s[i] != s[j])
j = result[j-1];