Skip to content

Instantly share code, notes, and snippets.

View weissjeffm's full-sized avatar

Jeff Weiss weissjeffm

View GitHub Profile
@weissjeffm
weissjeffm / hudson.repo
Created December 22, 2010 18:52
Repo file for hudson rhsm
[hudson-rhsm]
name=Red Hat Subscription Manager for Enterprise Linux 6 - $basearch
baseurl=http://hudson.rhq.lab.eng.bos.redhat.com:8080/hudson/job/subscription-manager_master/lastSuccessfulBuild/artifact/rpms/$basearch/
enabled=1
gpgcheck=0
http_caching=packages
@weissjeffm
weissjeffm / parse-json-example.clj
Created February 24, 2011 19:31
Example of parsing JSON in clojure - extract the array of numbers in the nested structure and add them up.
(def my-json "[\"zero\" \"first\" \"second\" {\"name\": \"third\" \"value\": [100 20 30]}]")
(-> (json/read-json myjson true) (nth 3) :value (->> (apply +)))
;; -> 150
@weissjeffm
weissjeffm / json.clj
Created March 29, 2011 13:53
How easy it is to use REST/json API in clojure :)
;;get all the names of the organizations
(->> (httpclient/get "http://f14-1.usersys.redhat.com:3000/api/organizations"
{:accept :json :basic-auth ["admin" "admin"]})
:body
json/read-json
(map #(-> :organization % :name)))
;; result
public static JSONObject getOwnerOfConsumerId(String server, String port, String prefix, String authenticator, String authenticatorPassword, String consumerId) throws JSONException, Exception {
JSONObject jsonOwner = null;
JSONObject jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(server, port, prefix, authenticator, authenticatorPassword,"/consumers/"+consumerId));
JSONObject jsonOwner_ = (JSONObject) jsonConsumer.getJSONObject("owner");
// Warning: this authenticator, authenticatorPassword needs to be superAdmin
jsonOwner = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(server, port, prefix, authenticator, authenticatorPassword,jsonOwner_.getString("href")));
return jsonOwner;
}
static public String getResourceUsingRESTfulAPI(String server, String port, String prefix, String authenticator, String password, String path) throws Exception {
@weissjeffm
weissjeffm / ruby-shadow-test.rb
Created May 2, 2011 18:55
How to test ruby-shadow
[root@host ~]# irb
irb(main):001:0> require "/usr/lib64/ruby/site_ruby/1.8/powerpc64-linux/shadow.so" #varies by platform - check 'rpm -ql ruby-shadow' for real location.
=> true
irb(main):004:0> Shadow::Passwd.getspent()
=> #<struct Struct::PasswdEntry sp_namp="root", sp_pwdp="$1$s9SM/aIM$ATv5Gcjkd2b/G/rkddVTq0", sp_lstchg=15095, sp_min=0, sp_max=99999, sp_warn=7, sp_inact=-1, sp_expire=-1, sp_flag=-1>
(execute getspent() repeatedly, should give a new user entry each time.
irb(main):009:0> Shadow::Passwd.setspent()
=> nil
(defn ^{Test {:dataProvider "mydata"}}
myfn [_ onearg]
(println (str "called with " onearg)))
(defn ^{DataProvider {:name "mydata"}} mydp [_]
(to-array-2d [[1] ["hi"] [3] [nil]]))
(gen-class-testng)
(defproject kalpana "1.0.0-SNAPSHOT"
:description "Kalpana automation"
:aot [#"^kalpana.tests"]
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[webui-framework "1.0.2-SNAPSHOT"]
[test_clj.testng "1.0.1-SNAPSHOT"]
[error.handler "1.1.0-SNAPSHOT"]
[inflections "0.4"]
[clj-http "0.1.1"]]
(defn random-facts []
(let [rand (java.util.Random.)
rand-255 #(.nextInt rand 255)
splice (fn [sep coll] (apply str (interpose sep coll)))
ip-prefix (splice "." (repeatedly 3 rand-255 ))
mac (splice ":" (repeatedly 6 #(Long/toHexString (rand-255))))] {
"dmi.bios.runtime_size" "128 KB",
"lscpu.cpu_op-mode(s)" "64-bit",
"uname.sysname" "Linux",
"distribution.name" "Fedora",
@weissjeffm
weissjeffm / katello-devel.repo
Created June 7, 2011 02:13
Yum repo file for katello CI builds
[katello-devel]
name=Katello Devel - $basearch
baseurl=http://hudson.rhq.lab.eng.bos.redhat.com:8080/hudson/job/katello-build/lastSuccessfulBuild/artifact/rpms/fedora-$releasever/$basearch/
enabled=1
gpgcheck=0
metadata_expire=120
@weissjeffm
weissjeffm / katello-gems-devel.repo
Created June 7, 2011 02:17
Yum repo file for katello CI builds (rubygem dependencies)
[katello-gems-devel]
name=Katello Ruby Gems - $basearch
baseurl=http://hudson.rhq.lab.eng.bos.redhat.com:8080/hudson/job/katello-gems/lastSuccessfulBuild/artifact/rpms/fedora-$releasever/$basearch/
enabled=1
gpgcheck=0
http_caching=packages