Skip to content

Instantly share code, notes, and snippets.

View julioterra's full-sized avatar

Julio Terra julioterra

View GitHub Profile
@julioterra
julioterra / Authenticated_HTTP_Request
Created January 4, 2011 17:21
Processing code that enables making of authenticated http requests from a Processing sketch. Developed to work with the Posterous API, but can be used with many other HTTP APIs that require authentication.
String username = "username_here";
String password = "password_here";
String posterous_url = "url_string_here";
String read_data = "";
void setup() {
try {
URLAuthReader.authenticated_http_request(posterous_url, username, password);
read_data = URLAuthReader.read_http_request();
println(read_data);
@julioterra
julioterra / Regex & Processing
Created January 11, 2011 16:19
Simple example of using matchAll method with regex patterns
// this pattern returns a match that starts with "display_date":" and features a date and time.
// It also returns two submatches one featuring the date while the other features the time
String[][] date_time_string = PApplet.matchAll(currentPage, "\"display_date\":\"([\\d][\\d][\\d][\\d][/][\\d][\\d][/][\\d][\\d])[ ]([\\d][\\d][:][\\d][\\d][:][\\d][\\d])");
// this pattern returns a match that starts with "body_html":" and features copy through the next
// instance of a quotation mark. It also returns four submatches that feature copy between the
// identifiers activity and location, location and people, people and description, description and the
// final quotation mark
String[][] message_bodies = PApplet.matchAll(currentPage, "\"body_html\":\".*?[Aa]ctivity:(.*?)[Ll]ocation:(.*?)[Pp]eople:(.*?)[Dd]escription:(.*?)(?=\")");
@julioterra
julioterra / Arduino_GSR_Code
Created September 21, 2011 04:34
Simple code for the Arduino to read data from a GSR sensor and turn on one to four leds based on the reading.
// save pin numbers to variables
int sensorPin = A0;
int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
void setup() {
// define which pins are used for input and output
pinMode(sensorPin, INPUT);
@julioterra
julioterra / gist:1258147
Created October 3, 2011 00:08
new object
my_object = Object.new
@julioterra
julioterra / gist:1258148
Created October 3, 2011 00:10
new class definition
class MyClass
def initialize(x)
code to initialize stuff goes here
end
end
@julioterra
julioterra / gist:1258236
Created October 3, 2011 01:21
class scope example
class MyClass #class scope
x = “class_scope” #class scope
def my_method_1 #class scope
x = 0 #my_method_1 scope
(0..5).each do |n| #my_method_1 scope
x += x #my_method_1 scope
end #class scope
end #class scope
def my_method_2 #class scope
x = 0 #my_method_2 scope
@julioterra
julioterra / gist:1258239
Created October 3, 2011 01:24
instance self example
class MyClass # class instance
def self.class_method # class instance
end # class instance
def self.class_method_2 # class instance
end # class instance
def instance_method # object instance
end # object instance
def instance_method_2 # object instance
end # object instance
end # class instance
@julioterra
julioterra / gist:1258245
Created October 3, 2011 01:34
different types of variables
class MyClass
@@class_variable #class-hierarchy variable
@class_instance_variable #class instance variable
attr_accessor :object_instance_variable #object instance attribute
#__variable with getter & setter
def self.class_method
local_method_variable #local method variable
@class_instance_variable #class instance variable
@@class_variable #class-hierarchy variable
@julioterra
julioterra / gist:1258249
Created October 3, 2011 01:37
attributes
attr_reader : var_with_getter
attr_writer : var_with_setter
attr_accessor : var_with_setter_and_getter
@julioterra
julioterra / gist:1258254
Created October 3, 2011 01:39
Types of Variables
#VARIABLE DESCRIPTION NAMESPACE
#var local variable scope-based
#$var global variable accessible anywhere
#@var instance variable self-based
#@@var class variable class hierarchy-based
#Const constant accessible anywhere with proper syntax