Skip to content

Instantly share code, notes, and snippets.

@Rhomboid
Rhomboid / fizzbuzz.c
Created October 10, 2012 23:07
Fizzbuzz in assembly on 9 architectures
#include <stdio.h>
int main(void)
{
int i;
for(i = 1; i <= 100; i++) {
if(i % 15 == 0) {
puts("FizzBuzz");
} else if(i % 3 == 0) {
puts("Fizz");
@Rhomboid
Rhomboid / gist:3966123
Created October 27, 2012 20:39
Huffman decoding
#include <memory>
#include <queue>
#include <string>
#include <utility>
#include <cassert>
#include <iostream>
#include <fstream>
class huffman {
public:
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <stdexcept>
class studentfile {
public:
studentfile(const std::string &filename);
--- orig/resources/reddit_res/data/reddit_enhancement_suite.user.js 2012-08-13 00:17:26.000000000 -0700
+++ resources/reddit_res/data/reddit_enhancement_suite.user.js 2012-11-01 14:09:45.769867200 -0700
@@ -6878,7 +6878,7 @@
],
checkToolbarLink: function(url) {
for (var i=0, len=this.toolbarFixLinks.length; i<len; i++) {
- if (url.indexOf(this.toolbarFixLinks[i]) != -1) return true;
+ if (url && url.indexOf(this.toolbarFixLinks[i]) != -1) return true;
}
return false;
@Rhomboid
Rhomboid / gist:3997891
Created November 2, 2012 00:43
project euler #4
#include <iostream>
static bool is_palendrome(int n)
{
if(n >= 100000)
return n / 100000 % 10 == n % 10 &&
n / 10000 % 10 == n / 10 % 10 &&
n / 1000 % 10 == n / 100 % 10;
else if(n >= 10000)
return n / 10000 % 10 == n % 10 &&
@Rhomboid
Rhomboid / 20121110.cpp
Created November 11, 2012 06:34
Simple file reading
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
using namespace std;
static unsigned binary_string_to_int(const string &s)
{
unsigned converted = 0;
@Rhomboid
Rhomboid / 20121119.cpp
Created November 19, 2012 15:14
Remove duplicates
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
vector<int> vec((istream_iterator<int>(cin)), istream_iterator<int>());
copy(vec.begin(), unique(vec.begin(), vec.end()), ostream_iterator<int>(cout, "\n"));
@Rhomboid
Rhomboid / heatmap.c
Created November 24, 2012 22:54
Simple ppm heatmap
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define COLORMAP_STEPS 2
typedef double colormap[3][COLORMAP_STEPS + 1][3];
/* interpolate 'val' from range [inlow, inhigh) into range [outlow, outhigh) */
static double interpolate(double val, double inlow, double inhigh, double outlow, double outhigh)
{
@Rhomboid
Rhomboid / tokenize.c
Created October 13, 2015 17:35
Tokenizing a string based on a set of delimiters into a dynamic array in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
size_t tokenize(const char *s, const char *delim, char ***tokenarray)
{
size_t size = 0, capacity = 4, wordlen;
const char *begin = s, *end;
char **tokens = malloc(capacity * sizeof(char *));
@Rhomboid
Rhomboid / gist:4261681
Created December 11, 2012 20:06
vector example
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
vector<double> getlist()
{