Skip to content

Instantly share code, notes, and snippets.

// #include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <algorithm>
// #include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;
@iwagaki
iwagaki / gist:279492054a50508bc2e0
Created February 19, 2015 17:01
bash read-only variable
#!/bin/bash
declare -r TEST="test" # read-only
TEST="!" # causes an error
echo ${TEST}
@iwagaki
iwagaki / gist:cd2380277200317d7500
Created February 19, 2015 16:54
LIFO converts to FIFO using a recursive function
#include <list>
#include <cstdio>
using namespace std;
class LIFO {
public:
void push_back(int a) {
mList.push_back(a);
}
#include <cstdio>
#define MARKER(fmt, ...) printf("%s: %d: %s(): " fmt "\n", __FILE__, __LINE__ , __func__, ##__VA_ARGS__)
int main(int argc, char *argv[])
{
MARKER("test %d", 100);
return 0;
}
@iwagaki
iwagaki / gist:f70912541bd1c7b938ae
Last active August 29, 2015 14:15
When does a sub-class override a super-class method?
#include <cstdio>
void checkVTBL0andCall(void* ptr)
{
long long* ptr_object = (long long*)ptr;
printf("ptr_object = %llx\n", (long long)ptr_object);
long long vptr = ptr_object[0];
printf("vptr = %llx\n", (long long)vptr);
@iwagaki
iwagaki / gist:83dba6453037860a49f7
Created February 19, 2015 16:22
factory method
class ClassA
{
public:
void destroy() const
{
delete this;
}
static ClassA* create()
{
@iwagaki
iwagaki / gist:f16af9f1c7be1e044133
Created February 18, 2015 17:35
How to initialize a vector
int a[] = {1, 2, 3, 4, 5};
vector<int> example(a, a + sizeof(a) / sizeof(a[0]));
@iwagaki
iwagaki / gist:2b5e612d1c93b6d88d51
Created February 18, 2015 17:21
Expand a shorten URI
require 'net/http'
require 'uri'
require 'pp'
def expandShortenURI(s)
uri = URI(s)
Net::HTTP.start(uri.host, uri.port) {|http|
response = http.head(uri.request_uri)
case response
when Net::HTTPRedirection
@iwagaki
iwagaki / gist:3629e22fc615dc677c72
Created January 27, 2015 15:51
Set adb with a sticky bit
sudo chown root:root adb
sudo chmod u+sx adb
@iwagaki
iwagaki / gist:4d0bd1e8f2df8c866141
Created January 27, 2015 10:17
beating self discovery syndrome (R)
person1<-function(x) { x }
person2<-function(x) { 2 * (x-10)}
plot(0, type="n", xlim=c(0,50), ylim=c(0,100), xlab="t", ylab="Performance")
curve(person1, 0, 50, add=T, col="blue")
curve(person2, 10, 50, add=T, col="red")
legend("topright", legend=c("Person with 1H", "Person with 2H"), pch=c(4,4), col=c("blue", "red"))
person1<-function(x) { 1 * exp(0.15 * x) - 1 }
person2<-function(x) { 4 * exp(0.15 * (x - 10)) - 4}
plot(0, type="n", xlim=c(0,50), ylim=c(0,500), xlab="t", ylab="Performance")