Skip to content

Instantly share code, notes, and snippets.

View andrewcrabb's full-sized avatar

Andrew Crabb andrewcrabb

View GitHub Profile
@andrewcrabb
andrewcrabb / boost_datetime_format.cpp
Last active January 4, 2019 18:18
Boost datetime to formatted output modified from http://bit.ly/2VwaARa http://cpp.sh/6mp4m
#include "boost/date_time/posix_time/posix_time.hpp"
#include <iostream>
#include <sstream>
std::string FormatTime(boost::posix_time::ptime now)
{
using namespace boost::posix_time;
static std::locale loc(std::wcout.getloc(),
new wtime_facet(L"%Y%m%d_%H%M%S"));
@andrewcrabb
andrewcrabb / boost_filesystem_0.cpp
Created September 14, 2018 16:28
Boost filesystem intro
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
namespace bf = boost::filesystem;
int open_ostream(bf::ofstream &t_stream, bf::path t_path, std::ios_base::openmode t_mode) {
t_stream.open(t_path, t_mode);
if (!t_stream.is_open()) {
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
namespace bf = boost::filesystem;
int open_ostream(bf::ofstream &t_stream, bf::path t_path, std::ios_base::openmode t_mode) {
t_stream.open(t_path, t_mode);
if (!t_stream.is_open()) {
@andrewcrabb
andrewcrabb / examples.sql
Last active May 16, 2016 16:57
Postgresql examples
# Grouping, case insensitive
SELECT lower("subjects"."name_last"), lower("subjects"."name_first"), lower("subjects"."history") FROM "subjects" GROUP BY lower(subjects.name_last), lower(name_first), lower(history) HAVING count(*) > 1;
# Another way
select name_last, name_first, history
from subjects
where (upper(name_last), upper(name_first), upper(history)) in
(select upper(name_last), upper(name_first), upper(history)
from subjects
group by upper(name_last), upper(name_first), upper(history)

|- ! Width | chain width:: |-

<?php
/**
* LDAP PHP Change Password Webpage
* @author: Matt Rude <http://mattrude.com>
* @website: http://technology.mattrude.com/2010/11/ldap-php-change-password-webpage/
*
*
* GNU GENERAL PUBLIC LICENSE
* Version 2, June 1991
@andrewcrabb
andrewcrabb / bash_commands.sh
Last active November 28, 2018 22:13
Bash useful commands
# Remove duplicate photos from Aperture masters
ls 2014/12/*/*\ \([12]\)* | while read dup; do orig=`echo $dup | sed -e 's/ (1)//'`; duorig=`du $orig | cut -f1`; dudup=`du $dup | cut -f1`; if (( dudup == duorig )); then echo $dup; rm $dup; fi; done
# Concatenate with given delimiter
ls -1 | tr "\\n" ","
# Find bad symlinks
find /target/dir -type l ! -exec test -e {} \; -print
# Use full line of grep results
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')