Skip to content

Instantly share code, notes, and snippets.

View smnplk's full-sized avatar
🌳
Just another forest critter trying to git tree and git log for winter

Simon Polak smnplk

🌳
Just another forest critter trying to git tree and git log for winter
View GitHub Profile
@smnplk
smnplk / example-effects-and-handlers.clj
Created August 17, 2020 15:07
Example of re-frame effect handlers and event handlers
(defonce interval-handler
(let [live-intervals (atom {})]
(fn handler [{:keys [action id frequency event]}]
(condp = action
:clean (doall
(map #(handler {:action :end :id %}) (keys @live-intervals)))
:start (swap! live-intervals assoc id (js/setInterval #(rf/dispatch event) frequency))
:end (do
(js/clearInterval (get @live-intervals id))
(swap! live-intervals dissoc id))))))
@smnplk
smnplk / advent_2017.clj
Last active December 4, 2017 03:50
Advent of Code 2017
# Day 1 part 1
# Inverse Captcha
(def input-str "77736991856689225253142335214746294932318813454849177823468674346512426482777696993348135287531487622845155339235443718798255411492778415157351753377959586612882455464736285648473397681163729345143319577258292849619491486748832944425643737899293811819448271546283914592546989275992844383947572926628695617661344293284789225493932487897149244685921644561896799491668147588536732985476538413354195246785378443492137893161362862587297219368699689318441563683292683855151652394244688119527728613756153348584975372656877565662527436152551476175644428333449297581939357656843784849965764796365272113837436618857363585783813291999774718355479485961244782148994281845717611589612672436243788252212252489833952785291284935439662751339273847424621193587955284885915987692812313251556836958571335334281322495251889724281863765636441971178795365413267178792118544937392522893132283573129821178591214594778712292228515169348771198167462495988252456944269678515277886142827218825358561772
@smnplk
smnplk / interpose.clj
Last active May 10, 2017 20:48
Interpose and interleave examples
(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)))
@smnplk
smnplk / Bob.js
Last active December 30, 2015 00:29
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(/\?$/)) }];
@smnplk
smnplk / mem.sh
Created May 31, 2012 00:41
bash script for display users memory usage
#!/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
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));
...
}
@smnplk
smnplk / vlado_gist
Last active August 29, 2015 14:07
Vladimirjev jedilnik (generator)
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