Skip to content

Instantly share code, notes, and snippets.

View larryv's full-sized avatar

Lawrence Velázquez larryv

View GitHub Profile
@larryv
larryv / gist:2379742
Created April 13, 2012 20:03
Determine whether a C string consists entirely of digits.
int is_valid_ref(char *arg)
{
do {
if (!isdigit(*arg))
return 0;
} while (*++arg);
return 1;
}
@larryv
larryv / logo.ps
Created April 22, 2012 22:17
MIT logo in PostScript
newpath
300.0 400.0 moveto
gsave
currentpoint translate
-241.66666666666669 0.0 rmoveto
108.33333333333334 0.0 rmoveto
gsave
currentpoint translate
-108.33333333333334 0.0 rmoveto
25.0 0.0 rmoveto
@larryv
larryv / gist:2632239
Created May 8, 2012 03:07
Completed COOL lexical analyzer
/*
* The scanner definition for COOL.
*/
/*
* Stuff enclosed in %{ %} in the first section is copied verbatim to the
* output, so headers and global definitions are placed here to be visible
* to the code in the file. Don't remove anything that was here initially
*/
%{
@larryv
larryv / gist:2640482
Created May 8, 2012 23:49
Cool string definition
/*
* String constants (C syntax)
* Escape sequence \c is accepted for all characters c. Except for
* \n \t \b \f, the result is c.
*
*/
\" {
string_buf_ptr = string_buf;
BEGIN(STRING);
@larryv
larryv / ex5.cc
Created May 12, 2012 04:49
Chapter 4, Exercise 5 from Stroustrup's "The C++ Programming Language"
/*
"The C++ Programming Language", Special Edition
Chapter 4, "Types and Declarations"
Exercise 5
"What, on your system, are the largest and the smallest values of the
following types: char, short, int, long, float, double, long double, and
unsigned."
12 May 2012
@larryv
larryv / ex5-1.cc
Created May 16, 2012 21:47
Convoluted C++ declarations
/*
"The C++ Programming Language", Special Edition
Chapter 5, "Pointers, Arrays, and Structures"
Exercise 1
"Write declarations for the following: a pointer to a character, an
array of 10 integers, a reference to an array of 10 integers, a
pointer to an array of character strings, a pointer to a pointer to
a character, a constant integer, a pointer to a constant integer,
and a constant pointer to an integer. Initialize each one."
#!/usr/bin/env ruby1.9
def merge_sort(a)
return a if a.length <= 1
l = (merge_sort(a[0...(a.length / 2)]) << Float::INFINITY).each
r = (merge_sort(a[(a.length / 2)...a.length]) << Float::INFINITY).each
Array.new(a.length) {|i| l.peek < r.peek ? l.next : r.next}
end
unsigned int count_inversions(unsigned int *ary, size_t len)
{
if (len <= 1) {
printf("base: %u\n", ary[0]);
return 0;
}
size_t i;
size_t l_len = len / 2;
Index: src/port1.0/portconfigure.tcl
===================================================================
--- src/port1.0/portconfigure.tcl (revision 102270)
+++ src/port1.0/portconfigure.tcl (working copy)
@@ -170,11 +170,44 @@
default configure.universal_cxxflags {[portconfigure::configure_get_universal_cflags]}
default configure.universal_ldflags {[portconfigure::configure_get_universal_ldflags]}
+# Internal function to set port dependencies for configure.compiler.
+# Defined up here so that it is available when setting the default value.
@larryv
larryv / gist:4694727
Created February 1, 2013 22:50
that's not right
[23:21:55] *** LordDeath has joined #macports
[23:22:04] <LordDeath> hi, is macports 2.1.3 out?
[23:22:19] <neverpanic> yes
[23:22:28] <LordDeath> I can't install it :-S
[23:22:31] <neverpanic> Raim: jmr_mp: can one of you fix the topic?
[23:22:42] <neverpanic> LordDeath: any error message?
[23:25:54] <LordDeath> http://pastebin.com/0mgBYNJH
[23:27:04] <larryv> can you run "port -d selfupdate" instead
[23:27:16] <LordDeath> as root?
[23:27:30] <larryv> as whatever you were doing before