Skip to content

Instantly share code, notes, and snippets.

@jbclements
jbclements / devres.rkt
Created March 28, 2012 17:24
devres.c only better....
(with-handlers
([cant-alloc -> NULL]
[cant-remap -> (devres-free the-box) NULL])
(define the-box (devres-alloc devm-ioremap-release, GFP_KERNEL))
(define remapped (ioremap-prot offset size flags))
(set-box! the-box remapped)
(devres-add dev the-box)
addr)
@jbclements
jbclements / stringlengths.c
Created March 28, 2012 20:32
One way to add string lengths
int numChars(char* word)
{
int i, j, sum = 0;
for(i = 0; word[i][j] != '\0'; i++)
{
for(j = 0; word[i][j] != '\0'; j++)
{
sum++;
}
@jbclements
jbclements / stringlengths.c
Created March 28, 2012 20:33
Another way to add string lengths
int numChars(char * strings[], int len) {
int sum = 0, i;
for (i = 0; i < len; i++) {
sum += strlen(strings[i]);
}
return sum;
}
@jbclements
jbclements / stringlengths.c
Created March 28, 2012 20:34
A third way to add string lengths
int numChars(char * strings[], int len) {
sumOf(lengths(strings));
}
@jbclements
jbclements / part-of-field_routines.f90
Created March 31, 2012 16:16
Extracted random subroutine from CMISS/cm tree
!================================================================================================================================
!
!>Initialises the interpolated point metrics for an interpolated point.
SUBROUTINE FIELD_INTERPOLATED_POINT_METRICS_INITIALISE(INTERPOLATED_POINT,INTERPOLATED_POINT_METRICS,ERR,ERROR,*)
!Argument variables
TYPE(FIELD_INTERPOLATED_POINT_TYPE), POINTER :: INTERPOLATED_POINT !A pointer to the interpolated point to initliase the interpolated point metrics for
TYPE(FIELD_INTERPOLATED_POINT_METRICS_TYPE), POINTER :: INTERPOLATED_POINT_METRICS !<On exit, a pointer to the interpolated point metrics that have been initialised
INTEGER(INTG), INTENT(OUT) :: ERR !<The error code
@jbclements
jbclements / bootstrap-carousel-excerpt.js
Created April 4, 2012 19:11
Excerpt from twitter/bootstrap docs/assets/js
@jbclements
jbclements / formula_installer-excerpt.rb
Created April 6, 2012 05:37
Excerpt from homebrew's formula_installer.rb
def link
if f.linked_keg.directory? and f.linked_keg.realpath == f.prefix
opoo "This keg was marked linked already, continuing anyway"
# otherwise Keg.link will bail
f.linked_keg.unlink
end
keg = Keg.new(f.prefix)
keg.link
rescue Exception => e
@jbclements
jbclements / widgets-excerpt.py
Created April 9, 2012 17:22
Excerpt from django forms/extras/widgets.py
class SelectDateWidget(Widget):
"""
A Widget that splits date input into three <select> boxes.
This also serves as an example of a Widget that has more than one HTML
element and hence implements value_from_datadict.
"""
none_value = (0, '---')
month_field = '%s_month'
day_field = '%s_day'
@jbclements
jbclements / oh-my-zsh.sh
Created April 11, 2012 06:54
chosen from oh-my-zsh repo
# Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" != "true" ]
then
/usr/bin/env ZSH=$ZSH zsh $ZSH/tools/check_for_upgrade.sh
fi
# Initializes Oh My Zsh
# add a function path
fpath=($ZSH/functions $ZSH/completions $fpath)
window.addEvent('domready', function() {
VariableFinder.initialize();
});
var VariableFinder = {
initialize: function() {
var programInput = $('programInput');
var output = $('output');
$('submitButton').addEvent('click', function() {