This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <utility> | |
#include <iostream> | |
struct exclusive { | |
exclusive() : o{true} { std::cout << this << " exclusive init\n"; } | |
~exclusive() { | |
if(owning()) | |
std::cout << this << " exclusive cleanup\n"; | |
else | |
std::cout << this << " exclusive no cleanup\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
int main() { | |
auto const cos = [](auto const& exp) { return [&]() { return std::cos(exp()); }; }; | |
auto const sin = [](auto const& exp) { return [&]() { return std::sin(exp()); }; }; | |
auto const term = [](auto const& x) { return [&]() { return x; }; }; | |
auto const eval = [](auto const& exp) { return exp(); }; | |
std::cout << eval(cos(sin(term(0.5 * M_PI)))) << '\n'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdlib.h> | |
#include<stdio.h> | |
typedef struct state_t { | |
int current_line; | |
int heading_level; | |
token* previous_token; | |
} state; | |
state* state_with(state* s) /* just for readability when invoking */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////////////////////////////////////////////////////////////////////////////// | |
// dyn.cc - compiled and linked as a dynamic library | |
/////////////////////////////////////////////////////////////////////////////// | |
#include <iostream> | |
extern "C" void fun() | |
{ | |
std::cout << "BOOYA!!1! fun() invoked!\n"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# polymorphism in bash ? | |
prepare_c() { | |
cp ~/c_skeleton $1 | |
cp ~/c_makefile_skeleton $1 | |
} | |
prepare_bash() { | |
cp ~/bash_skeleton $1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T, size_t N> | |
T* end_of(T (&arr)[N]) | |
{ | |
return &arr[0]+N; | |
} | |
// ... | |
int arr[42]; | |
std::fill(arr, end_of(arr), 25); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
union ufloat { | |
float f; | |
char b[sizeof(float)]; | |
}; | |
int main(int argc, char* argv[]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from_dot() | |
{ | |
[ $# -gt 0 ] && local FROM="$@"; | |
sed '/[{}]/d; s/^\s*\|\s*\[[^]]*\]\s*\|\s*;\s*$//g; s/\s/_/g; s/\s*->\s*/ /' $FROM; | |
} | |
from_dot graph.dot |tsort #|tac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System { | |
class Exception<T> : Exception { | |
public Exception() { } | |
public Exception(string message) : base(message) { } | |
public Exception(string message, Exception inner) | |
: base(message, inner){ } | |
} | |
} | |
namespace App { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# git read eval print loop | |
P='git> '; | |
echo -e -n "$P"; | |
while read L; do | |
if [ "$L" = "quit" -o "$L" = q ]; then | |
break; | |
fi; | |
git "$L"; |
OlderNewer