Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
# USAGE:
@CraZySacX
CraZySacX / merger.py
Created February 19, 2014 14:24
Python script that aids with merging upstream projects with origin. Useful for github forks.
#!/usr/bin/python3
import argparse
import os
from os import environ
from subprocess import check_call
# Store the current directory
owd = os.getcwd()
# Setup the supported command-line arguments
@CraZySacX
CraZySacX / git.clj
Last active November 24, 2020 19:23
Clojure git wrapper
(ns org.ozias.git
(:require [me.raynes.conch :refer (with-programs)]))
(def ^:private git-porcelain
["add" "am" "bisect" "branch" "bundle" "checkout" "cherry-pick" "citool"
"clean" "clone" "commit" "describe" "diff" "fetch" "format-patch"
"gc" "grep" "gui" "init" "log" "merge" "mv" "notes" "pull" "push"
"rebase" "reset" "revert" "rm" "shortlog" "show" "stash" "status"
"submodule" "tag"])
@CraZySacX
CraZySacX / max.scala
Last active August 29, 2015 14:00
I think an anon function would work, but can't seem to find the proper syntax...
// Original....
def max(xs: List[Int]): Int = {
def findMax(curr: Int, l: List[Int]): Int = {
if (l.isEmpty)
curr
else if (l.head > curr)
findMax(l.head, l.tail)
else
findMax(curr, l.tail)
}
@CraZySacX
CraZySacX / target.clj
Created April 30, 2014 16:03
Clojure to Haskell
(defn- target
"generate a target from a user and host string.
If user and host are nil, evaluates to localhost.
If host is nil, evaluates to user@localhost.
If user is nil, evaluates to host.
Otherwise evaluates to user@host."
[user host]
(let [host (if (string? host) host "localhost")
user (if (string? user) (str user "@") "")]
(str user host)))
@CraZySacX
CraZySacX / handler.clj
Created May 7, 2014 18:23
Sorting by int value rather than String value in a mixed sequence
(ns wgetjava.handler
(:require [clojure.java.io :as io]
[clojure.string :as str]
[org.ozias.cljlibs.shell.shell :refer :all]
[org.ozias.cljlibs.utils.core :refer :all])
(:import (clojure.lang PersistentArrayMap PersistentVector)))
(def ^{:private true :doc "cookies temp file path"}
cookies-path (to-path (tmpdir) "cookies.txt"))
@CraZySacX
CraZySacX / quarter-round1
Last active August 29, 2015 14:01
Which is preferable from a functional perspective?
(defn- quarter-subround
"### quarter-subround
A quarter subround.
Represents a vector of two values:
[w = (x + y mod 2<sup>32</sup>)
((w ^ z) <<< shift)]"
{:added "0.2.0"}
[[x y z] shift]
@CraZySacX
CraZySacX / macro-arg-eval.clj
Created October 15, 2014 20:47
Evaluating macro arguments
(def post-cfg {:ctx "/account POST"
:dba :start
:reqfn (as-admin (account-post))
:expected-status 200
:expected-message :localized/account-created})
(defmacro edn-req [{:keys [ctx dba reqfn sep
expected-status expected-message]
:or {sep true}}]
`(context
@CraZySacX
CraZySacX / query_demo.clj
Created November 11, 2014 20:09
Datomic query demo
(comment
; Pull the datomic api into this namespace
(require '[datomic.api :as d])
(require '[glitter.entity.util :refer :all])
; Setup a connection to the transactor
(def conn (d/connect uri))
; Get a database value
(def db-now (d/db conn))
@CraZySacX
CraZySacX / fuck.fish
Created March 30, 2015 19:09
Inspired by a bash alias that did the same thing....
function fuck
echo sudo $history[1]
eval command sudo $history[1]
end