Skip to content

Instantly share code, notes, and snippets.

@beakr
beakr / random_game_range.cpp
Created April 26, 2014 16:29
Generate a random integer in a range with C++.
int main(...)
{
srand(time(NULL));
while (true) {
int nmin = 220;
int nmax = 550;
int x = nmin + (std::rand() % (nmax - nmin + 1));
printf("%i\n", x);
}
for (int i = 0; i < spawnedFish.size(); i++) {
IND_Entity2d * fish = spawnedFish.at(i);
for (int j = 0; j < 20; j++) {
if ((x - j) == fish->getPosX()) {
x -= 10;
}
else if ((x + j) == fish->getPosX()) {
x += 10;
}
}
@beakr
beakr / opene.sh
Last active December 7, 2021 23:39
Open Windows file explorer on a directory with Cygwin.
#!/bin/bash.exe
# This script opens a given directory up in the Windows file explorer. I did
# this to make it easy when opening directories in the Cygwin system using
# the explorer.
#
# To install:
#
# $ touch /usr/bin/opene
# $ vim /usr/bin/opene
@beakr
beakr / UnrealLogging.cc
Created April 2, 2014 18:50
Simple debug logging macros for Unreal Engine 4.
/**
* Log a green debug message in the corner of the game screen. Generally
* used for situations in which an operation has completed successfully.
*/
#define BL_LOG_GREEN(str) (GEngine->AddOnScreenDebugMessage(-1, 5.f, \
FColor::Green, \
TEXT(str)))
/**
* Log a yellow debug message in the corner of the game screen. Generally
@beakr
beakr / cpp11_syntastic.vim
Created March 9, 2014 21:23
Debug C++11 with syntastic.
let g:syntastic_cpp_compiler_options = '-std=c++0x'
@beakr
beakr / get_output.py
Created March 9, 2014 18:00
Get command output in Python.
import subprocess
# rstrip() is used to remove the line terminator at the end of most command output.
host = subprocess.check_output(['command', .. args ..], stderr=subprocess.STDOUT).rstrip()
@beakr
beakr / task.py
Created March 1, 2014 18:56
Task running decorator.
tasks = []
def task(meth):
tasks.append(meth)
def new(*args): return meth(*args)
return new
def call_task(task_id):
(tasks[id])()
def init():
# ... Initialize entities ...
def update():
# ... Update entities ...
@beakr
beakr / readfile.cc
Created February 23, 2014 20:24
Always keep this Gist close to your heart. You will love it forever.
char * readfile(const char * f)
{
ifstream in(f, std::ifstream::binary);
in.seekg(0, in.end);
int size = in.tellg();
in.seekg(0);
char * buf = new char[size];
in.read(buf, size);
@beakr
beakr / fork.c
Created February 23, 2014 03:45
#include <stdio.h>
int main(void)
{
int pid;
pid = fork();
if(pid > 1) {
printf("I AM THE PARENT PROCESS\n");
} else if(pid == 0) {
printf("I AM THE CHILD PROCESS\n");