Skip to content

Instantly share code, notes, and snippets.

@arjunmenon
arjunmenon / Android.md
Created October 10, 2017 09:20
Filter adb logcat output by app name and pretty colors
adb logcat | grep `adb shell ps | grep com.package | cut -c10-15`
@arjunmenon
arjunmenon / Ruby Snippets.md
Last active November 14, 2017 16:16
Practical Ruby snippets
  1. Split sentence preserve punctuation
    https://stackoverflow.com/a/15687656/2096740

Use scan (throw strip in there to get rid of trailing spaces).

s = "I am a lion. Hear me roar! Where is my cub? Never mind, found him."
s.scan(/[^\.!?]+[\.!?]/).map(&:strip) # => ["I am a lion.", "Hear me roar!", "Where is my cub?", "Never mind, found him."]

  1. Simple detect puncutation in string
@arjunmenon
arjunmenon / strip HTML tags
Created October 16, 2017 19:13 — forked from awesome/strip HTML tags
ruby strip HTML tags
# copied from (thanks!): http://codesnippets.joyent.com/posts/show/615
str = <<HTML_TEXT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>Application error</h1>
<p>Change this error message for exceptions thrown outside of an action (like
in Dispatcher setups or broken Ruby code) in public/500.html</p>
var Client = require('./upnp_client.js')
var client = new Client('http://192.168.1.6:49152/description.xml');
console.log(client);
// Get the device description
client.getDeviceDescription(function(err, description) {
if(err) throw err;
console.log("starting device description module")
console.log(description);
@arjunmenon
arjunmenon / python_server
Created January 1, 2018 13:20
Python server monitring any HTTP requests
#!/usr/bin/env python
# Read requests from HTTP methods GET, POST, PUT, DELETE, NOTIFY or any other custom method
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@arjunmenon
arjunmenon / vin_to_gif.rb
Created April 10, 2018 19:54 — forked from seyhunak/vin_to_gif.rb
Vine MP4 to GIF Converting using Ruby
# space150 vine-to-GIF
# given a vine.co uri, downloads the MP4 and creates an image sequence / GIF from it
# requires ruby, ffmpeg, and imagemagick
require 'open-uri'
require 'nokogiri'
id = ARGV[0]
# try to convert from URL to id.
@arjunmenon
arjunmenon / Hash.from_xml
Created June 6, 2018 21:07 — forked from huy/Hash.from_xml
Convert xml to hash using Nokogiri
# USAGE: Hash.from_xml(YOUR_XML_STRING)require 'rubygems'
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#123129
7
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
@arjunmenon
arjunmenon / create_xml.rb
Created June 12, 2018 12:01 — forked from kimjoar/create_xml.rb
Simple Ruby DSL to generate XML
require './xmldsl'
Twitter = Struct.new :name, :avatar, :text
twitters = []
5.times { twitters << Twitter.new("Jonas", "/profile.png", "Hello World!") }
xml = XML.generate do
html do
body do
twitters.each do |tw|
@arjunmenon
arjunmenon / Readme.md
Last active June 12, 2018 15:19
Glade DSL

Run test_glade.rb
Run basic.rb