Skip to content

Instantly share code, notes, and snippets.

//
// bit_vector.h
//
// Created by identifer on 5/12/14.
// Copyright (c) 2014 identifer. All rights reserved.
//
#ifndef BIT_VECTOR_H
#define BIT_VECTOR_H
@id-0x76adf1
id-0x76adf1 / ffr.c
Created December 20, 2013 12:09 — forked from cloudwu/ffr.c
#include <stdint.h>
#include <stdlib.h>
// assert(RAND_MAX >= 0x7fff)
float
random_0_to_1() {
union {
uint32_t d;
float f;
} u;
@id-0x76adf1
id-0x76adf1 / scope_guard.hpp
Last active December 12, 2015 03:28
scope guard
// from http://mindhacks.cn/2012/08/27/modern-cpp-practices/
#ifndef SCOPE_GUARD_H
#define SCOPE_GUARD_H
#include <functional>
class scope_guard {
private:
scope_guard(const scope_guard&);
@id-0x76adf1
id-0x76adf1 / date.cpp
Created January 10, 2013 06:30
Write a class that has three unsigned members representing year, month, and day. Write a constructor that takes a string representing a date. This constructor should handle a variety of formats, such as January 1, 1900, 1/1/1900, Jan 1, 1900, and so on.
#include "date.h"
@id-0x76adf1
id-0x76adf1 / gist:4377380
Last active December 10, 2015 03:58
Determine whether one of the two vectors of ints is the prefix of the other.
#include <iostream>
#include <vector>
typedef std::vector<int> int_vec;
// the size of ivec1 is less than or equal to the size of ivec2
static bool is_prefix_impl(const int_vec& ivec1, const int_vec& ivec2)
{
auto it1 = ivec1.begin();
auto it2 = ivec2.begin();
@id-0x76adf1
id-0x76adf1 / gist:4377108
Created December 26, 2012 01:47
Keep track of the largest number of times a single repetition occurs and which word is repeated.
#include <iostream>
#include <string>
int main(int arc, char* argv[])
{
int max_count = 0;
std::string max_count_word;
int count = 0;
std::string prev_word;