Skip to content

Instantly share code, notes, and snippets.

//Const Quick-Ref
int variable_integer = 39;
const int constant_integer = 42;
const int * var_ptr_to_const_int = &constant_integer;
int const * also_var_ptr_to_const_int = &constant_integer;
int * const const_ptr_to_var_int = &variable_integer;
int const * const const_ptr_to_const_int = &constant_integer;
int & ref_to_int = variable_integer;
const int & ref_to_const_int = constant_integer;
#include <iostream>
#include <fstream>
using namespace std;
int main(void) {
fstream foo1;
foo1.open("seek.bin", ios_base::in | ios_base::out | ios_base::binary | ios_base::trunc);
int i;
for(i = -100; i < 99; i ++) {
#include <iostream>
using namespace std;
void printy(char* t) {
unsigned long* v; // Swab on a little-endian machine
v = (unsigned long*) t;
cout << "0x" << hex << *v << "; // " << t << endl;
}
#include <openssl/rand.h>
#include <stdio.h>
int main(void) {
unsigned char c;
int i;
for(i = 0; i < 100; i++) {
RAND_pseudo_bytes(&c, 1);
printf("Trial %d: %hhu %hhu\n", i, c, (c < 24 ? ~c : c));
}
sub score {
return length($_[0]) > 8 ? 8 - length($_[0]) : length($_[0]);
}
my @s;
for my $o (`iconv -l`) {
chomp $o;
my(@aliases) = map(uc, split(/ /, $o));
tr/A-Z0-9//cd for @aliases;
print((sort { score($b) <=> score($a) } @aliases)[0] . ": $o\n");
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;
struct f {
char x[16];
};
@scooby
scooby / ios modes.cpp
Created February 8, 2009 05:35
tests ios modes when file doesn't exist; which ones will create file
#include <fstream>
#include <iostream>
using namespace std;
void test(ios_base::openmode bits, char* name) {
fstream f;
f.open(name, bits);
cout << "Tried " << name;
if(f.is_open()) {
@scooby
scooby / svg embed code.html
Created February 11, 2009 05:18
code to embed an svg with alternate
<object data="star.svg" type="image/svg+xml" id="svg" width="450" height="350">
<img src="star.png" alt="Star">
</object>
@scooby
scooby / multimap_test.cpp
Created February 13, 2009 23:35
multimap test insert and iterating
#include <iostream>
#include <map>
using namespace std;
int main(void) {
multimap<int, int> mm;
for(int i = 20; i; i--)
mm.insert(make_pair((i * 3) & 7 + i, (i * 5) & 7));
multimap<int, int>::iterator it = mm.begin();
@scooby
scooby / boolorder.cpp
Created February 13, 2009 23:36
turns out false < true
#include <iostream>
using namespace std;
int main(void) {
if(false < true)
cout << "False is less than true." << endl;
if(false > true)
cout << "False is greater than true." << endl;
if(true < false)