Skip to content

Instantly share code, notes, and snippets.

  1. Express ideas directly in code; §3.2.
  2. Define classes to represent application concepts directly in code; §3.2.
  3. Use concrete classes to represent simple concepts and performance-critical components; §3.2.1.
  4. Avoid ‘‘naked’’ new and delete operations; §3.2.1.2.
  5. Use resource handles and RAII to manage resources; §3.2.1.2.
  6. Use abstract classes as interfaces when complete separation of interface and implementation is needed; §3.2.2.
  7. Use class hierarchies to represent concepts with inherent hierarchical structure; §3.2.4. Section 3.5 Advice 85
@Nathaniel100
Nathaniel100 / timer.cpp
Created July 7, 2016 02:06
c++11 timer class
class Timer {
public:
Timer() : beg_(clock_::now()) {}
void reset() { beg_ = clock_::now(); }
double elapsed() const {
return std::chrono::duration_cast<second_>(clock_::now() - beg_).count();
}
private:
typedef std::chrono::high_resolution_clock clock_;
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@Nathaniel100
Nathaniel100 / color_printf.c
Created July 11, 2016 08:29
Color text in terminal applications in UNIX
#define RED "\x1B[31m"
#define GRN "\x1B[32m"
#define YEL "\x1B[33m"
#define BLU "\x1B[34m"
#define MAG "\x1B[35m"
#define CYN "\x1B[36m"
#define WHT "\x1B[37m"
#define RESET "\x1B[0m"
printf("This is " RED "red" RESET " and this is " BLU "blue" RESET "\n");
@Nathaniel100
Nathaniel100 / base64.cpp
Created July 12, 2016 05:02
base64 cpp
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
@Nathaniel100
Nathaniel100 / build.gradle
Created July 21, 2016 06:53
android ndk gradle
ndk {
platformVersion = 9
moduleName = 'plasma'
toolchain = 'clang'
CFlags.addAll(['-Wall'])
ldLibs.addAll(['m', 'log', 'jnigraphics'])
}
@Nathaniel100
Nathaniel100 / build.gradle
Last active July 26, 2016 03:16
top level gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// dagger2
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
@Nathaniel100
Nathaniel100 / build.gradle
Last active July 28, 2016 05:45
app gradle
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'
// If enabled jack, You should use annotationProcessor dependency scope instead of apt. See http://android-developers.blogspot.fi/2016/05/android-studio-22-preview-new-ui.html (search for annotationProcessor)
// annotationProcessor "com.google.dagger:dagger-compiler:$gradle.dagger2Version
android {
compileSdkVersion gradle.ext.compileSdkVersion
buildToolsVersion gradle.ext.buildToolsVersion
@Nathaniel100
Nathaniel100 / setting.gradle
Created July 29, 2016 05:54
setting gradle
gradle.ext.dagger2Version = "2.2"
gradle.ext.retrofit2Version = "2.1.0"
gradle.ext.ageraVersion = "1.1.0"
gradle.ext.okHttp3Version = "3.4.1"
gradle.ext.rxJavaVersion = "1.1.8"
gradle.ext.rxAndroidVersion = "1.2.1"
@Nathaniel100
Nathaniel100 / hideSoftKeyboard.java
Created August 3, 2016 03:28
hide soft keyboard
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}