Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/ruby
puts
File.open(ARGV[0]).each do |line|
line = line.split
if line[0] == "IBOutlet"
puts "[#{line[2].tr('*;','')} release];"
elsif line[1] and line[1].include? "*"
puts "[#{line[1].tr('*;','')} release];"
end
// Javascript Benchmark Declaring len inside and outside of a for loop
// Populate array with 0..100
var arr = []
for (var i=0; i<1e3; ++i) { arr[i] = i; }
// Declare len outside of the for
function outfor(a) {
var len = a.length;
for (var i=0; i<len; ++i);
}
require 'rubygems'
require 'hpricot' # hpricot-0.6.164
html = <<END
<html><head></head><body><table>
<tr><td>R0C0</td><td>R0C1</td><td>R0C2</td><td>R0C3</td></tr>
<tr><td>R1C0</td><td>R1C1</td><td>R1C2</td><td>R1C3</td></tr>
<tr><td>R2C0</td><td>R2C1</td><td>R2C2</td><td>R2C3</td></tr>
</table></body></html>
END
# DATA is a global that is actually a
# File object containing the data
# after __END__ in the current
# script file. WHOA!
puts DATA.read
__END__
I can put anything I want
after the __END__ symbol
and access it with the
int str_cmp( char *str1, char *str2 ) {
if ( !*str1 && !*str2 )
return 0;
char a = *str1, b = *str2;
if( a >= 'a' && a <= 'z' )
a -= 32;
if( b >= 'a' && b <= 'z' )
b -= 32;
@JosephPecoraro
JosephPecoraro / gist:6563
Created August 21, 2008 14:02
Strip similarities at the start and end of two strings. [ruby]
# Strip Similarities between two strings
module Kernel
#
# strip_similiar
# Strips the similiarities at the start and end of each
# of the given strings, returning a list of both of the
# stripped strings.
#
@JosephPecoraro
JosephPecoraro / gist:5049
Created August 12, 2008 14:42
Parse DOM Data
//
// Function: allData(node)
// Concatenate all the text data of a node's children.
//
function allData(node) {
var data = "";
if (node && node.firstChild) {
node = node.firstChild;
if (node.data) { data += node.data; }
while (node = node.nextSibling) {
@JosephPecoraro
JosephPecoraro / gist:4397
Created August 7, 2008 13:18
Benchmarking String Concatenation
// Benchmarking String Concatenation Comparing
// 1. Array.join
// 2. String concatenation with '+'
// Test Functions
function test_join(content) { return ['output.push(', content, ');'].join(''); };
function test_str_concat(content) { return 'output.push(' + content + ');'; };
// Test Strings
var SHORT_STRING = 'test';
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active September 10, 2023 10:12
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
#include <stdio.h>
void str_squeeze(char *s) {
int i, j;
char last = '\0';
for ( i = j = 0; s[i]; last = s[i++] )
if ( s[i] != last )
s[j++] = s[i];
s[j] = '\0';
}