Skip to content

Instantly share code, notes, and snippets.

void main() {
int n = 600851475143;
var l = new List<int>();
for (int i = 0; i < n; i++) {
l.add(i);
}
}
/* Prints:
Exhausted heap space, trying to allocate 1073741856 bytes.
Unhandled exception:
@boustrophedon
boustrophedon / gist:10428231
Created April 10, 2014 22:14
dart vs js. the most important test
// dart version
void main() {
List<int> l = [1,10,5];
l.sort();
print(l); // [1, 5, 10]
}
// js version
var l = [1, 10, 5];
l.sort();
@boustrophedon
boustrophedon / undef_eval_order.cpp
Created July 5, 2014 18:07
the evaluation order of i and ++i is undefined in a single expression. the book said that it's so "compilers have freedom for optimization" but they give warnings anyway so...
#include <iostream>
int main() {
int i = 0;
std::cout << i << " " << ++i << std::endl;
return 0;
}
@boustrophedon
boustrophedon / splaytreevaluemap.dart
Created October 8, 2014 21:11
splay tree map w/ values as comparators
import 'dart:core';
import 'dart:collection';
class Test {
SplayTreeMap m;
Test() {
m = new SplayTreeMap<String, RTest>(_compare);
}
int _compare(String s1, String s2) {
CC=g++
CFLAGS=-Wall -Werror
LDFLAGS=-lopencv_core -lopencv_highgui
all: main
OBJS = main.o
main: $(OBJS)
$(CC) -o $@ $(OBJS) $(LDFLAGS)
foreach (NavMeshAgent a in agents)
{
if (a.GetComponent<Animator>() != null)
{
Animator anim = a.GetComponent<Animator>();
anim.SetFloat("VSpeed", a.velocity.z);
anim.SetFloat("HSpeed", a.velocity.x);
if (Input.GetButtonDown("Fire3")) {
Linking CXX executable /home/hcs/ros_wk/devel/lib/image_listener/image_listener_node
CMakeFiles/image_listener_node.dir/src/image_listener.cpp.o: In function `ImageListener::image_callback(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
image_listener.cpp:(.text._ZN13ImageListener14image_callbackERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE[_ZN13ImageListener14image_callbackERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEE]+0x51d): undefined reference to `threshold_image(cv::Mat)'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/hcs/ros_wk/devel/lib/image_listener/image_listener_node] Error 1
make[1]: *** [image_listener/CMakeFiles/image_listener_node.dir/all] Error 2
make: *** [all] Error 2
- lib.rs
"""
mod my_mod;
"""
- my_mod/
- mod.rs
"""
#[cfg(test)]
mod test;
"""
@boustrophedon
boustrophedon / example.rs
Last active June 11, 2016 20:07
ecs ideas
fn main() {
let world = World::new(); // or builder pattern
let physics = PhysicsSystem::new(); // this would create the ncollide world inside
// world takes ownership of systems
world.add_system(physics);
// etc.
world.run();
struct Entity {
pub id: usize,
pub ver: usize,
}
impl Eq for Entity {
fn eq(self, other: Entity) {
return (self.id == other.id) && (self.ver == other.ver);
}
}