Skip to content

Instantly share code, notes, and snippets.

View deltamualpha's full-sized avatar
🥔

David Ashby deltamualpha

🥔
View GitHub Profile
@deltamualpha
deltamualpha / gist:5218827
Created March 22, 2013 03:49
I suck at clojure.
(defn magic [row]
(if (map? (first row)) (for [x row] (into [] (flatten (seq x)))) (into [] x)))
(defn collapser [incoming]
(reduce (fn [a b] (conj a (magic b))) [["header" "information"]] (remove nil? incoming)))
;for an input like
;([:a a :b b] nil nil [{:c c, :d d} {:e e, :f f}] nil [:a g :b h]) =>
;[["test" "two"] [:a "a" :b "b"] ([:c "c" :d "d"] [:e "e" :f "f"]) [:a "g" :b "h"]]
;but what I want is
@deltamualpha
deltamualpha / gist:5639611
Last active December 17, 2015 16:30
A way to run a number of different tag queries in wordpress and then sort the results, putting the queries that match the most tags at the top.
$queries_array = {$query_1, $query_2, $query_n};
$merged_array = array_reduce($queries_array, array_merge);
$uniques = array();
$counter = array();
foreach ( $merged_array as $current ) {
$counter[current->id] += $counter[current->id];
$uniques[current->id] = $current; // pulls out unique only
}
@deltamualpha
deltamualpha / gist:5971827
Created July 11, 2013 01:37
There has got to be a better way.
(defn get-attributes [html]
(map #(into {} %)
(map #(remove nil? %)
(map #(if (dom/attributes? %) [(:name (dom/attributes %)) (:value (dom/attributes %))])
(map dom/node-seq
(xpath/lookup-nodeset "//form[@class=\"download\"]" html))))))
@deltamualpha
deltamualpha / gist:9918757
Last active August 29, 2015 13:57 — forked from fernandoaleman/gist:4551494
A one-liner to delete the crud files that s3fs leaves in your mounted s3 directories after you've quit using s3fs
s3cmd ls --recursive s3://BUCKET_NAME |\
ruby -rdate -ne 'date, time, size, uri = $_.split; puts uri if size == "0" && uri[-1,1] != "/" && !uri.include?(".")' |\
xargs s3cmd del
@deltamualpha
deltamualpha / gist:614e1799f97c8be298f8
Last active August 29, 2015 14:06
php phar download puppet
# install a phar file from a remote server directly
define php::phar ($url, $insecure = false, $target = $title) {
$split = split($url, '/')
$filename = $split[-1]
# for wget bug workarounds
if ($insecure == true) {
$wget_options = "--no-check-certificate"
}
@deltamualpha
deltamualpha / gist:c3a191260352f24eb74e
Created September 6, 2014 21:21
create a proper extension file for an installed php module
define php::conf {
if $::lsbdistcodename == 'precise' {
$php_build = '20090626'
file { "/etc/php5/conf.d/${title}.ini":
ensure => present,
owner => 'root',
group => 'root',
mode => '0644',
content => template("php/conf.d/${title}.ini"),
@deltamualpha
deltamualpha / keybase.md
Created April 21, 2016 21:42
keybase.md

Keybase proof

I hereby claim:

  • I am deltamualpha on github.
  • I am deltamualpha (https://keybase.io/deltamualpha) on keybase.
  • I have a public key ASAHcIGA69GoZ2GE70pQbpKsWbRWeipiheYAq53ctGapLwo

To claim this, I am signing this object:

@deltamualpha
deltamualpha / any_base_palindromes.js
Last active May 20, 2016 02:30
This problem was presented to me: given a list of numbers, 1-1000, can you name the smallest base in which each one is a palindrome?
var palindrome_test = function(array) {
for (var i = 0; i <= array.length - 1; i++) {
if (array[i] !== array[array.length - i - 1]) {
return false;
}
}
return true;
}
var int2base = function(int, base) {
@deltamualpha
deltamualpha / pyramid.js
Created May 20, 2016 00:40
another coding challenge that came up recently: given an odd number, return a centered pyramid with a base that width.
var pyramid = function(width) {
if (width % 2 == 0) {
console.log("odd numbers only, please");
return;
}
var gaps = '';
for (var i = ((width-1)/2); i >= 0; i--) {
gaps += ' ';
}
var hashes = '#';
// Peculiar balance
// ================
// Can we save them? Beta Rabbit is trying to break into a lab that contains the
// only known zombie cure – but there’s an obstacle. The door will only open if
// a challenge is solved correctly. The future of the zombified rabbit
// population is at stake, so Beta reads the challenge: There is a scale with an
// object on the left-hand side, whose mass is given in some number of units.
// Predictably, the task is to balance the two sides. But there is a catch: You
// only have this peculiar weight set, having masses 1, 3, 9, 27, … units. That
// is, one for each power of 3. Being a brilliant mathematician, Beta Rabbit