Skip to content

Instantly share code, notes, and snippets.

@labeneator
labeneator / lsof
Created February 27, 2013 16:07
Lsof output for a leaky program
$ lsof -p $(pgrep leaky)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
leaky 16095 laban cwd DIR 0,30 4096 10936796 /home/laban/devel/private/learning/c/leak_descriptors
leaky 16095 laban rtd DIR 252,1 4096 2 /
leaky 16095 laban txt REG 0,30 11267 10919599 /home/laban/devel/private/learning/c/leak_descriptors/leaky
leaky 16095 laban mem REG 252,1 1811128 19136595 /lib/x86_64-linux-gnu/libc-2.15.so
leaky 16095 laban mem REG 252,1 149280 19136932 /lib/x86_64-linux-gnu/ld-2.15.so
leaky 16095 laban 0u CHR 136,19 0t0 22 /dev/pts/19
leaky 16095 laban 1u CHR 136,19 0t0 22 /dev/pts/19
leaky 16095 laban 2u CHR 136,19 0t0 22 /dev/pts/19
@labeneator
labeneator / gist:5049168
Last active December 14, 2015 07:18
Playing around with variables in gdb
$ sudo gdb -p $(pgrep leaky)
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
@labeneator
labeneator / lsof-output2.sh
Created February 27, 2013 16:21
lsof after changing program variables with gdb
$ lsof -p $(pgrep leaky)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
leaky 16095 laban cwd DIR 0,30 4096 10936796 /home/laban/devel/private/learning/c/leak_descriptors
leaky 16095 laban rtd DIR 252,1 4096 2 /
leaky 16095 laban txt REG 0,30 11267 10919599 /home/laban/devel/private/learning/c/leak_descriptors/leaky
leaky 16095 laban mem REG 252,1 1811128 19136595 /lib/x86_64-linux-gnu/libc-2.15.so
leaky 16095 laban mem REG 252,1 149280 19136932 /lib/x86_64-linux-gnu/ld-2.15.so
leaky 16095 laban 0u CHR 136,19 0t0 22 /dev/pts/19
leaky 16095 laban 1u CHR 136,19 0t0 22 /dev/pts/19
leaky 16095 laban 2u CHR 136,19 0t0 22 /dev/pts/19
@labeneator
labeneator / gist:5049227
Created February 27, 2013 16:25
GDB for loop to close leaky fds
Leaks all over the place
$ lsof -p $(pgrep leaky)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
leaky 16095 laban cwd DIR 0,30 4096 10936796 /home/laban/devel/private/learning/c/leak_descriptors
leaky 16095 laban rtd DIR 252,1 4096 2 /
leaky 16095 laban txt REG 0,30 11267 10919599 /home/laban/devel/private/learning/c/leak_descriptors/leaky
leaky 16095 laban mem REG 252,1 1811128 19136595 /lib/x86_64-linux-gnu/libc-2.15.so
leaky 16095 laban mem REG 252,1 149280 19136932 /lib/x86_64-linux-gnu/ld-2.15.so
leaky 16095 laban 0u CHR 136,19 0t0 22 /dev/pts/19
leaky 16095 laban 1u CHR 136,19 0t0 22 /dev/pts/19
$ ./leaky
Iteration 1
Iteration 2
Iteration 5
Iteration 6
Iteration 2147483647
Iteration -2147483648
Iteration -2147483647
@labeneator
labeneator / noaa_gfs.R
Created March 30, 2013 19:59
A quick R script
# load datasets
library(fields)
library(ncdf)
# Load land data
landFrac <-open.ncdf("land.netcdf")
land <- get.var.ncdf(landFrac,"LAND_surface")
@labeneator
labeneator / R_ggplot_with_vline.R
Created April 4, 2013 21:16
Plotting two dataframes that share only one field between them
events <- read.csv("events.csv")
> head(events)
timestamp event
1 2013-04-03 22:59:05.061Z A
2 2013-04-03 22:59:05.061Z B
3 2013-04-03 22:59:07.109Z C
4 2013-04-03 22:59:07.115Z D
5 2013-04-03 22:59:07.209Z E
@labeneator
labeneator / charting.R
Created April 11, 2013 21:34
Better prime finding methods? i.e with a better big-O performance?
require("ggplot2")
# data load
n_squared = read.csv("nth.csv", header=T)
n_modulo = read.csv("nth_modulo.csv", header=T)
n_modulo$nth_log <- log(n_modulo$nth)
n_modulo$time_log <- log(n_modulo$time)
n_squared$time_log <- log(n_squared$time)
n_squared$nth_log <- log(n_squared$nth_prime)
/*
# php -v
PHP 5.3.15 with Suhosin-Patch (cli) (built: Jul 31 2012 14:49:18)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
Takes 0.6 seconds per hash at 100000 rounds
# time php test.php
Original password: password
Salt (hex) : 8454780bed43
@labeneator
labeneator / gist:6833040
Created October 4, 2013 21:26
RMySQL install error on OSX
** installing vignettes
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'RMySQL', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/usr/local/Cellar/r/3.0.1/R.framework/Versions/3.0/Resources/library/RMySQL/libs/RMySQL.so':
dlopen(/usr/local/Cellar/r/3.0.1/R.framework/Versions/3.0/Resources/library/RMySQL/libs/RMySQL.so, 6): Library not loaded: libmysqlclient.18.dylib
Referenced from: /usr/local/Cellar/r/3.0.1/R.framework/Versions/3.0/Resources/library/RMySQL/libs/RMySQL.so
Reason: image not found
Error: loading failed
Execution halted