Skip to content

Instantly share code, notes, and snippets.

Alec Benzer AlecBenzer

Block or report user

Report or block AlecBenzer

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
View git-branch-cleanup
#!/bin/bash
set -u
git fetch --all --quiet
for b in $(git for-each-ref refs/heads --format="%(refname:short)"); do
if [[ ! $(git cherry -v origin/master $b | grep "^+") ]]; then
git branch -D $b
elif git diff --exit-code --quiet "origin/master...${b}"; then
git branch -D $b
fi
View test.md
View .md
int x = new int(5);
int x = new int(5);
View none
<pre class="prettyprint">
<code class="language=c++ hljs cs">
int x = <em>new</em> int(5);
</code>
</pre>
```c++
int x = new int(5);
```
View gist:9651803
buckets = defaultdict(list)
for z, root in root_from.iteritems():
closest = next((k for k in buckets if abs(k - root) < 1e-3), None)
if closest:
buckets[closest].append(z)
else:
buckets[root].append(z)
roots = buckets.keys()
View gist:8963583
#include <unistd.h>
#include <stdio.h>
int main() {
int i;
pid_t pid = fork();
if (pid == 0) {
printf("I am the child. I'm going to print 'Hello, World!' 15 times\n");
for (i = 0; i < 15; ++i) {
printf("Hello, World!\n");
View gist:6693523
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = fork();
if (pid == 0) {
printf("I'm the child -- about to run ls -a -l\n");
execlp("ls", "ls", "-a", "-l", (char*)NULL);
} else {
printf("I'm the parent -- about to run pwd\n");
View select.go
package main
import (
"fmt"
"math/rand"
"reflect"
)
func worker(n int, ch chan int) {
count := rand.Intn(5) + 3
View list.c
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node* next;
} node;
node* new_node() {
node* n = malloc(sizeof(node));
View gist:5296913
void renderText(TTF_Font* font, string text) {
SDL_Color color = {255, 0, 0};
SDL_Surface* rendered = TTF_RenderText_Solid(font, text.c_str(), color);
// slightly modified from http://stackoverflow.com/questions/5289447/using-sdl-ttf-with-opengl
GLint colors = rendered->format->BytesPerPixel;
GLenum format;
if (colors == 4) { // alpha
if (rendered->format->Rmask == 0x000000ff) {
format = GL_RGBA;
You can’t perform that action at this time.