Skip to content

Instantly share code, notes, and snippets.

@taboularasa
taboularasa / ParseXML.java
Created May 19, 2009 14:27
Parsing / Reading XML file in Java
package net.viralpatel.java.xmlparser;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@taboularasa
taboularasa / using apt-key add
Last active October 12, 2021 20:27
alternative to `apt-key add` for installing Debian packages
curl -sLS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install --no-install-recommends yarn
@taboularasa
taboularasa / caesar.rb
Created May 4, 2021 02:32
implement caesar cipher
def transpose(message, mapping)
message.chars.map {|e| mapping[e]}.join
end
puts "encode or decode?"
selected_action = gets.chomp
puts "what is the key?"
key = gets.chomp
puts "what is your message?"
message = gets.chomp
# Although our analytics team produces a styling algorithm
# it can't always capture everything a customer has requested.
# For example, a customer might write in their note to the stylist
# "Please no pink!!!". The algorithm can't always tell that,
# so it might suggest pink clothes for the customer.
#
# Suppose the stylist has the ability to manually filter out
# attributes the customer wants to avoid. What we'd like
# you to do is, given a list of items, and a list of
@taboularasa
taboularasa / keybase.md
Created August 24, 2016 17:36
keybase.md

Keybase proof

I hereby claim:

  • I am taboularasa on github.
  • I am davidelliott (https://keybase.io/davidelliott) on keybase.
  • I have a public key whose fingerprint is 7948 9BB4 CE88 AFE3 F563 501A BC46 D821 0F21 0480

To claim this, I am signing this object:

@taboularasa
taboularasa / Erode.java
Created March 23, 2009 01:40
Open the last saved jpeg image Save it as a new jpeg image with slightly more compression Repeat 600 times
import com.sun.image.codec.jpeg.*;
PImage img;
int numberOfFrames = 600;
void setup()
{
size(1024,768);
}
@taboularasa
taboularasa / flatten.rb
Created June 25, 2016 07:48
flatten an Array
require 'minitest/autorun'
##
# Implement flatten
#
# ruby -Ilib:test flatten.rb
def flatten(accumulator, element)
if element.is_a? Array
element.each {|e| flatten(accumulator, e)}
# hubot-scripts test
# usage:
# hubot cmd ls -la
#
fs = require('fs')
spawn = require('child_process').spawn
module.exports = (robot) ->
robot.respond /(cmd) (.*) (.*)/i, (msg) ->
cmd = msg.match[2]
arg = msg.match[3]
#!/usr/bin/env ruby
require 'csv'
# This assumes:
# - Ruby 1.9's CSV library, if you are using 1.8, use FasterCSV.
#
# https://raw.github.com/hadley/data-baby-names/master/baby-names.csv
csv_fname = "baby-names.csv"
require 'rubygems'
require 'google_drive'
# set your username and password
login = GoogleDrive.login(GoogleDrive::USERNAME, GoogleDrive::PASSWORD)
# set your spreadsheet key
sheet = login.spreadsheet_by_key(GoogleDrive::SPREADSHEET)
sheet.worksheets.each do |ws|
p ws.title