Instantly share code, notes, and snippets.

View advent_2017.clj
# Day 1 part 1
# Inverse Captcha
(def input-str "77736991856689225253142335214746294932318813454849177823468674346512426482777696993348135287531487622845155339235443718798255411492778415157351753377959586612882455464736285648473397681163729345143319577258292849619491486748832944425643737899293811819448271546283914592546989275992844383947572926628695617661344293284789225493932487897149244685921644561896799491668147588536732985476538413354195246785378443492137893161362862587297219368699689318441563683292683855151652394244688119527728613756153348584975372656877565662527436152551476175644428333449297581939357656843784849965764796365272113837436618857363585783813291999774718355479485961244782148994281845717611589612672436243788252212252489833952785291284935439662751339273847424621193587955284885915987692812313251556836958571335334281322495251889724281863765636441971178795365413267178792118544937392522893132283573129821178591214594778712292228515169348771198167462495988252456944269678515277886142827218825358561772
View interpose.clj
(defn my-interpose [element coll]
(rest (flatten (for [e coll] [element e]))))
(defn my-interleave [coll1 coll2]
(flatten (map vector coll1 coll2)))
; Both tasks are kind of similar, so we could use the interpose function to implement interleave
(defn my-interleave2 [element coll]
(my-interpose coll (repeat (count coll) element)))
View gist:1c2f2aa091cc29103398
render: function() {
var time_columns = _.range(1,this.state.num_columns_init +1).map(function(n) {
if(this.state.removed_columns.contains(n)) /*if column was marked for removal, don't render it*/
return null;
return <TimeColumn columnIndex={n} workers={this.state.workers} key={n}/>;
3 }.bind(this));
...
}
View vlado_gist
vlado_konzumira = ['palačinke', 'hood burger', 'humus',
'piščanca od jakliča', 'ribji namaz',
'polento', 'hruškino nabodalo', 'kosmiče na žaru']
vladotov_menu = Date::DAYNAMES.inject({}) do |menu, day|
menu[day.downcase.to_sym] = "Vlado bo danes jedel #{vlado_konzumira[rand(vlado_konzumira.size)]}"
menu
end
puts vladotov_menu
View Bob.js
var Bob = function() {
this.hey = function(message){
var respond_with = function(answer,regex_matches){
if(regex_matches)
return answer;
}
var responders = [
function() { return respond_with("Fine, be that way!", message.match(/^\s*$/)) },
function() { return respond_with("Woah, chill out!", message.match(/[A-Z]/) && message.toUpperCase() == message)},
function() { return respond_with("Sure.", message.match(/\?$/)) }];
View mem.sh
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "WARNING: you have to run as root if you want to see all users"
fi
echo "Printing only users that current memmory usage > 0 Kilobytes "
all=0
for username in `ps aux | awk '{ print $1 }' | tail -n +2 | sort | uniq`
do
pids=`ps aux | grep $username | awk -F" " '{print $2}'`
total_memory=0