Skip to content

Instantly share code, notes, and snippets.

(define (fast-mult a b)
(cond ((= b 0) 0)
((even? b) (fast-mult (+ a a) (/ b 2)))
(else (+ a (fast-mult a (- b 1))))))
@mrunalp
mrunalp / ldetect
Created September 12, 2012 00:13
Detect env vars to rid of under the current cart directory
#!/bin/bash
# Arguments
whitelist=$@
# Constants
repo_root=/opt/myrepos
# Stolen from util
function convert_cart_name_to_namespace_id {
@mrunalp
mrunalp / util
Created September 14, 2012 17:16
Get list of framework carts
diff --git a/stickshift/abstract/abstract/info/lib/util b/stickshift/abstract/abstract/info/lib/util
index 86fae75..1e8dcad 100755
--- a/stickshift/abstract/abstract/info/lib/util
+++ b/stickshift/abstract/abstract/info/lib/util
@@ -33,6 +33,9 @@ function get_stop_order {
echo $(get_component_order "tac")
}
+function get_installed_framework_carts {
+ (cd $OPENSHIFT_HOMEDIR; ls -d {diy-0.1,jbossas-7,jbosseap-6.0,jenkins-1.4,nodejs-0.6,perl-5.10,php-5.3,python-2.6,ruby-1.8,ruby-1.9,zend-5.6} 2>/dev/null)
#!/usr/bin/env ruby
require '/var/www/openshift/broker/config/environment'
CloudUser.find_all(nil).each { |u|
u.applications.each { |a|
if a.scalable
puts a.name
a.elaborate_descriptor
carts = a.embedded.keys.dup
carts << a.framework
@mrunalp
mrunalp / cartgen.rb
Created May 23, 2013 04:09
Cartridge generator
#!/usr/bin/env ruby
# Usage ./cartgen.rb <cart_name>
require 'fileutils'
require 'logger'
$log = Logger.new(STDERR)
cart_name = ARGV[0]
cart_short_name = cart_name.upcase
# Base on the Fedora image created by Matthew
FROM mattdm/fedora
# Install the JBoss Application Server 7
RUN yum install -y nodejs npm
ADD . /src
RUN cd /src; npm install
@mrunalp
mrunalp / gist:7570688
Created November 20, 2013 20:45
Supporting files
[mrunal@localhost nodejs]$ cat package.json
{
"name": "docker-fedora-nodejs",
"private": true,
"version": "0.0.1",
"description": "Node.js Hello World app on Fedora using docker",
"author": "Mrunal Patel <[email protected]>",
"dependencies": {
"express": "*"
}
#!/usr/bin/env node
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function(connection) {
@mrunalp
mrunalp / ip_adress.rb
Created March 18, 2014 21:03
Get IP address for an interface in ruby.
require 'socket'
require 'ipaddr'
# From ioctls.h
SIOCGIFADDR = 0x8915
def ip_address(iface)
sock = UDPSocket.new
buf = [iface,""].pack('a16h16')
sock.ioctl(SIOCGIFADDR, buf);
package main
import (
"log"
"os"
"syscall"
)
func main() {
syscall.ForkLock.Lock()