Skip to content

Instantly share code, notes, and snippets.

@spaghetti-
spaghetti- / gist:3406503
Created August 20, 2012 18:34
working in base 256
#base any 10->higher i suppose
def basec(x, b):
r = []
while(x != 0):
r.append(x % b)
x = x // b
return r[::-1]
@spaghetti-
spaghetti- / gist:4010008
Created November 4, 2012 03:31
simple opengl
//renders a cube on a purple background
#include <GL/glut.h>
#include <GL/GL.h>
#include <GL/GLU.h>
void display_gl(){
glClearColor(1.0f, 0.0f, 1.0f, 1.0f); //purple
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
#include <malloc.h>
typedef struct{
int i;
short s[2];
} PACKET;
int main(void){
PACKET *mp, m = {4, 1, 0};
char *fp, *tp;
@spaghetti-
spaghetti- / gist:4374386
Last active December 10, 2015 03:28
how to join a list of strings in c (comma separated). surprisingly worked at the first try
char *joinlist(char **list, char *obj, int count)
{
char *str = NULL;
size_t total = 0;
size_t length = 0;
int i;
for(i = 0; i < count; i++){
total += strlen(list[i]);
}
total += count - 1;
#define MODULE_NAME "streams"
#define MAKING_STREAMS
#include "src/mod/module.h"
#include "streams.h"
#undef global
static Function *global = NULL;
#!/usr/bin/python
from bs4 import BeautifulSoup
import sys, urllib, textwrap
class URLOpener(urllib.FancyURLopener):
def __init__(self, *args):
self.version = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"
urllib.FancyURLopener.__init__(self, *args)
d2replayparser.exe 92802440.dem
Match-id: 92802440
Mode: 1
Winner: 2
Duration: 3006.666748
SKERDI (npc_dota_hero_rattletrap) 0/0 0 i1 i2 i3 i4 i5 i6
Sexy.777 (npc_dota_hero_lion) 0/0 0 i1 i2 i3 i4 i5 i6
Sexy.S4suke (npc_dota_hero_morphling) 0/0 0 i1 i2 i3 i4 i5 i6
ViCTORAKOS (npc_dota_hero_crystal_maiden) 0/0 0 i1 i2 i3 i4 i5 i6
Sexy.Sossi|Yko (npc_dota_hero_lycan) 0/0 0 i1 i2 i3 i4 i5 i6
#include <map>
int main(void)
{
std::map<int, std::string> test;
test.insert(std::pair<int, std::string>(23, "string here"));
return 0;
}
################
struct c{
int id;
std::string name;
};
std::vector<c> clist;
std::vector<c>::iterator i;
i = std::find(c.begin(), c.end(), 2 /* any integer value */)
if(i != c.end())
@spaghetti-
spaghetti- / gist:4557649
Last active December 11, 2015 06:09
find_if usage
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
struct person{
int id;
std::string name;
};