Skip to content

Instantly share code, notes, and snippets.

#include <mutex>
#include <condition_variable>
using namespace std;
class semaphore
{
public:
semaphore(int count_ = 0) : count{count_}
{}
@sguzman
sguzman / git-alias
Created December 16, 2014 23:54
Some useful git alias
# core {{{
[core]
editor = /usr/bin/vim
excludesfile = /Users/npaolucci/.gitignore_global
pager=less -x4
#}}}
# user {{{
[user]
email = [email protected]
@sguzman
sguzman / custom-reader.cpp
Last active August 29, 2015 14:12
Custom reader for input
#include <iostream>
#include <cstdlib>
namespace {
static inline void init(void) {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
}
constexpr static const size_t BUFF{256};
@sguzman
sguzman / taskwarrior
Last active August 29, 2015 14:17
Attempt to get taskwarrior to recognize project when inside a git repo dir
# Taskwarrior simple checker for git repo
# If it finds one, use the project dir as the project filter
function t() {
git show &> /dev/null
retval=$?
if [ $retval -eq "0" ]; then
dir=$(git rev-parse --show-toplevel)
project=$(basename $dir)
@sguzman
sguzman / converDecto26ary
Created March 20, 2015 18:45
Testing my conversion 10->26. Will work on a more general framework for dec -> any-ary
#include <iostream>
#include <cstdlib>
#include <array>
using namespace std;
template <typename A>
using conref = const A&;
template <typename A, size_t sz>
@sguzman
sguzman / work on leetcode problem
Created March 20, 2015 21:44
Failed attempt to get a quasi-conversion working for a leetcode problem
#include <iostream>
#include <cstdlib>
#include <array>
#include <stdlib.h>
using namespace std;
template <typename A>
using conref = const A&;
@sguzman
sguzman / qsort.cxx
Created March 24, 2015 02:38
A qsort implementation
#include <iostream>
#include <cstdlib>
#include <vector>
#include "pretty_print.hxx"
using namespace std;
template <typename A>
using conref = const A&;
@sguzman
sguzman / string-search.cxx
Created March 24, 2015 22:25
Attempt at implementing fast string search algorithms, with naive search there for reference
#include <iostream>
#include <cstdlib>
#include "pretty_print.hxx"
using namespace std;
static inline bool naive(char* haystack, char* needle) {
for (int i = 0; haystack[i] != '\0'; ++i) {
if (haystack[i] == needle[0]) {
@sguzman
sguzman / overlap.js
Created April 3, 2015 17:04
Succinct overlap checker in javascript
/**
* @param {number} a
* @param {number} b
* @param {number} c
* @param {number} d
* @return {bool}
*/
function overlap(a, b, c, d) {
return b >= c && d >= a;
}
@sguzman
sguzman / string-subclass.cxx
Created April 3, 2015 21:24
Use variadic templates to setup a general constructor in subclass
//
// Created by SGuzman on 4/3/2015.
//
#include <iostream>
static inline void print(const char* str) {
std::cout << str << std::endl;
}
class stuff : public std::string {