Skip to content

Instantly share code, notes, and snippets.

Chris beakr

Block or report user

Report or block beakr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@beakr
beakr / random_game_range.cpp
Created Apr 26, 2014
Generate a random integer in a range with C++.
View random_game_range.cpp
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);
}
View algorithm_that_doesnt_work.cpp
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 Aug 29, 2015
Open Windows file explorer on a directory with Cygwin.
View opene.sh
#!/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 Apr 2, 2014
Simple debug logging macros for Unreal Engine 4.
View UnrealLogging.cc
/**
* 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 Mar 9, 2014
Debug C++11 with syntastic.
View cpp11_syntastic.vim
let g:syntastic_cpp_compiler_options = '-std=c++0x'
@beakr
beakr / get_output.py
Created Mar 9, 2014
Get command output in Python.
View get_output.py
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 Mar 1, 2014
Task running decorator.
View task.py
tasks = []
def task(meth):
tasks.append(meth)
def new(*args): return meth(*args)
return new
def call_task(task_id):
(tasks[id])()
View script.py
def init():
# ... Initialize entities ...
def update():
# ... Update entities ...
@beakr
beakr / readfile.cc
Created Feb 23, 2014
Always keep this Gist close to your heart. You will love it forever.
View readfile.cc
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);
View fork.c
#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");
You can’t perform that action at this time.