Skip to content

Instantly share code, notes, and snippets.

@Sangrail
Sangrail / lifetimes.cpp
Last active January 10, 2024 17:30
Showing c++ lifetimes
// Type your code here, or load an example.
#include<iostream>
#include<string>
#include <vector>
#include <array>
struct LifeTime {
// default constructor
LifeTime() {
@Sangrail
Sangrail / ExportKindle.js
Last active June 15, 2019 18:39 — forked from jkubecki/ExportKindle.js
Amazon Kindle Export
var db = openDatabase('K4W', '3', 'thedatabase', 5 * 1024 * 1024);
getAmazonCsv = function() {
// Set header for CSV export line - change this if you change the fields used
var csvData = "ASIN,Title,Authors,PurchaseDate\n";
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM bookdata;', [], function(tx, results) {
var len = results.rows.length;
@Sangrail
Sangrail / gist:a413c9f8827a9998ce5ef43aea449efc
Created August 1, 2018 13:39
GIT Force PULL overwrite local copy
git fetch --all
git reset --hard origin/master
git pull origin master

Keybase proof

I hereby claim:

  • I am sangrail on github.
  • I am jaycoleman (https://keybase.io/jaycoleman) on keybase.
  • I have a public key whose fingerprint is C3A4 27EA 3C15 10F1 816F C3A3 5BC0 4AA8 671E 356C

To claim this, I am signing this object:

@Sangrail
Sangrail / gist:02b1338f4b6c73ff512eab6cc48d0464
Last active June 14, 2016 12:23
Floating point representation
```
#include <iostream>
#define EPSILON 1.0e-7
#define flt_equals(a, b) (fabs((a)-(b)) < EPSILON)
using namespace std;
typedef struct {
#include <iostream>
#include <map>
using namespace std;
map<int, char> lookup = {{1, 'a'}, {2, 'b'}, {3, 'c'}};;
void hanoi(int numDisks, int source, int destination, int open)
{
if(numDisks>0)
int factorialI(int n)
{
int f = 1;
for(int i = 1; i <= n; i++){
f *= i;
}
return f;
}
@Sangrail
Sangrail / gist:618b365112d3266c0d8d1356dc85a4fb
Created June 9, 2016 22:08
Windows VC++ CommandLine build
Step 1:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat"
From current directory mkdir
-asm
-obj
-exe
Step 2: Create build.bat
public sealed class Singleton1
{
private static Singleton1 _instance;
private Singleton1() {}
public static Singleton1 Instance
{
get {
return _instance ?? (_instance = new Singleton1()); //null coalescing
@Sangrail
Sangrail / Disposal.cs
Created June 3, 2016 18:09
Smart Disposal pattern
public static class Disposable
{
///Create a higher order function (HOF) - accept a Functor as a parameter
public static TResult Using<TDisposable, TResult>(
Func<TDisposable> factory,
Func<TDisposable, TResult> map)
where TDisposable : IDisposable
{
using (var disposable = factory())
{