Skip to content

Instantly share code, notes, and snippets.

@iwagaki
iwagaki / gist:7899d4619bb5ec05668a
Created January 27, 2015 10:12
hopfield model
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cassert>
#include <stdint.h>
#include <vector>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
@iwagaki
iwagaki / gist:cda175a2dd77333e5ac5
Created January 27, 2015 09:42
getimeofday v.s. clock_gettime
#include <cstdio>
#include <cstdlib>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
int main()
{
struct timeval now;
@iwagaki
iwagaki / gist:f9e1d26560f941362617
Created January 27, 2015 09:35
gcc hello world
#include <stdio.h>
__attribute__((section(".plt"))) main;
__attribute__((constructor, destructor)) void _() {
if (main) {
__attribute__((cleanup(puts))) char _[] = "world!";
} else {
__attribute__((cleanup(printf))) char _[] = "Hello, ";
main = 0xc3;
@iwagaki
iwagaki / gist:ad0a9939f3d434cdeb89
Created January 27, 2015 09:28
Get a path name by a fd (file descriptor)
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define VERIFY(x) if (!(x)) { assert(x); abort(); }
#include <cstdio>
#include <cstdlib>
#include <ctime>
template <typename T> void swap(T* a, T* b) {
T tmp = *a;
*a = *b;
*b = tmp;
}
@iwagaki
iwagaki / gist:5f6882b208a4c1c2864b
Created January 27, 2015 09:21
recursive strlen
#include <cstdio>
int my_strlen(char* str) {
if (*str == 0)
return 0;
else
return my_strlen(str + 1) + 1;
}
int main() {
@iwagaki
iwagaki / gist:235807342b355c2fbca7
Created January 27, 2015 09:17
reverse string
#include <cstdio>
#include <cstdlib>
#include <string.h>
void reverse(char *str)
{
char* ptr_start = str;
char* ptr_end = str + strlen(str) - 1;
while (ptr_start < ptr_end)
@iwagaki
iwagaki / gist:47f999e2231545cea964
Last active August 29, 2015 14:14
Allow empty message in git commit
git commit -a --allow-empty-message -m ""
@iwagaki
iwagaki / gist:add7a2c5c6e2d4811a65
Last active August 29, 2015 14:14
Summarize odd numbers
#include <cstdio>
#include <cstdlib>
#include <string.h>
int summarize_odd_numbers(int a, int b)
{
int sum = 0;
for (int c = a; c <= b; c++)
{
if ((c & 0x1) == 1)
@iwagaki
iwagaki / gist:1256975
Last active September 27, 2015 10:38
ibus 1.3.9 + cherry-pick e3140b7206d409419faa0c8bfa50f25ad3644cd0 + this fix
diff --cc bus/ibusimpl.c
index da24354,79dbf27..0000000
--- a/bus/ibusimpl.c
+++ b/bus/ibusimpl.c
@@@ -196,11 -316,43 +196,42 @@@ bus_ibus_impl_set_trigger (BusIBusImpl
IBUS_CONTROL_MASK,
hotkey);
}
-#endif
}