Skip to content

Instantly share code, notes, and snippets.

@whoshuu
whoshuu / folding.md
Created November 16, 2017 19:42
Folding Subsequence

Folding subsequence

This problem actually goes by another name, but to throw off cheaters, I'll use "folding" to describe the following property:

A folding sequence is a sequence of numbers where the difference between consecutive numbers in the sequence alternate in sign. A difference of 0 is defined to have no sign, so any sequence with consecutive repeating numbers is by definition a non-folding sequence.

To illustrate, these are folding sequences:

1
#!/usr/bin/env bash
# add repository for g++-5
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
# add repository for clang-3.7
sudo add-apt-repository -y "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.7 main"
wget --quiet -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
@whoshuu
whoshuu / weekly-noodler-1.md
Last active March 23, 2016 18:02
Weekly Noodler #1 - 3/22

Folding subsequence

This problem actually goes by another name, but to throw off cheaters, I'll use "folding" to describe the following property:

A folding sequence is a sequence of numbers where the difference between consecutive numbers in the sequence alternate in sign. A difference of 0 is defined to have no sign, so any sequence with consecutive repeating numbers is by definition a non-folding sequence.

To illustrate, these are folding sequences:

1
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -2
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
for(auto i = 0; i < 100000; ++i) {
// This is a basic for-loop, duh!
}
#include <vector>
class range {
public:
typedef std::vector<long>::const_iterator const_iterator;
range(long end) : range(0, end) {}
range(long begin, long end, long step = 1) {
long diff = end - begin;
@whoshuu
whoshuu / basic_zmq.cpp
Created May 18, 2015 17:36
Sending a protobuf message using zmq
#include <iostream>
#include <zmq.hpp>
#include "basic.pb.h"
int main(int argc, char** argv) {
zmq::context_t context{1};
zmq::socket_t sender{context, ZMQ_PAIR};
zmq::socket_t receiver{context, ZMQ_PAIR};
sender.bind("tcp://*:*");
@whoshuu
whoshuu / curlget.cpp
Created March 31, 2015 06:44
Example libcurl GET request
#include <curl/curl.h>
#include <string>
size_t writeFunction(void *ptr, size_t size, size_t nmemb, std::string* data) {
data->append((char*) ptr, size * nmemb);
return size * nmemb;
}
int main(int argc, char** argv) {
auto curl = curl_easy_init();

Keybase proof

I hereby claim:

  • I am whoshuu on github.
  • I am huu (https://keybase.io/huu) on keybase.
  • I have a public key ASAYE35aWCYUWw6wKdnEzgDJmwgArqrQ1m9OfR-rBSfzLAo

To claim this, I am signing this object:

@whoshuu
whoshuu / bootstrap.sh
Last active November 19, 2015 01:05
Bootstrap installation of pip, virtualenv, and virtualenvwrapper
#!/bin/bash
###########################################################################################
# bootstrap.sh
#
# To run directly from web:
# wget -O - https://gist.githubusercontent.com/whoshuu/11159710/raw/bootstrap.sh | bash
# Else:
# ./bootstrap.sh
#