Skip to content

Instantly share code, notes, and snippets.

View PetrGlad's full-sized avatar
🚶‍♂️
.

Petr Gladkikh PetrGlad

🚶‍♂️
.
  • 20:10 (UTC +04:00)
View GitHub Profile
@PetrGlad
PetrGlad / run-java
Created August 18, 2012 10:32
Enable java remote debugger (JDWP, openjdk)
java -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n ClassName
@PetrGlad
PetrGlad / many-to-many-select.clj
Created October 10, 2012 12:57
Many to many select with Korma
(select users
(fields :users.first_name)
(join user_to_role (= :users_to_roles.user_id :users.id))
(join role (= :users_to_roles.role_id :roles.id))
(fields [:roles.name :role_name]))
@PetrGlad
PetrGlad / timelapse.sh
Created October 27, 2012 12:20
Create timelapse video or animation with mencoder
mencoder mf://timelapse-*.jpg -mf fps=24:type=jpeg -noskip -of lavf -lavfopts format=mkv -ovc x264 -lavcopts vglobal=1:coder=0:vcodec=x264:vbitrate=100000 -vf eq2=1.2:0.9:0.0:1.0,scale=1280:-2 -o out.mkv
@PetrGlad
PetrGlad / machinarium.clj
Last active October 12, 2015 15:58
Solving Machinarium switchboard
(ns petrglad.machinarium)
(defn abs [x] (if (< x 0) (- x) x))
(defmulti sgn type)
(defmethod sgn java.lang.Long [x]
(if (> x 0) +1 -1))
(defmethod sgn clojure.lang.Keyword [x]
(cond
(= x :↓) -1
# From http://www.joescat.com/backup/disk_image.html
mount -o username=name,password=secret //server/share backup
dd if=/dev/sda | gzip -c | split -b 638m - backup/backup.img.gz.
# Restoration
cat backup/backup.img.gz.* | gzip -dc | dd of=/dev/sda
@PetrGlad
PetrGlad / hiccup-zipper.clj
Created February 25, 2013 03:06
hiccup HTML zipper
(require ['clojure.zip :as 'zip])
(defn hiccup-zip
"Returns a zipper for Hiccup forms, given a root form."
[root]
(let [children-pos #(if (map? (second %)) 2 1)]
(zip/zipper
vector?
#(drop (children-pos %) %) ; get children
#(into [] (concat (take (children-pos %1) %1) %2)) ; make new node
@PetrGlad
PetrGlad / LinkedList.java
Created July 3, 2013 15:20
Yet another interview task: Linked list
package lab;
public class LinkedList<T> {
class Node {
public final T value;
public final Node prev;
public Node(Node prev, T value) {
this.prev = prev;
@PetrGlad
PetrGlad / init.el
Created July 7, 2013 13:17
My emacs init
;;;-----------------------------------------------------------------
; From http://clojure.roboloco.net/?tag=paredit
(setq inhibit-startup-message t) ;; No splash screen
;; (setq initial-scratch-message nil) ;; No scratch message
;; (tool-bar-mode nil) ;; No toolbars
;; Create backup files in .emacs-backup instead of everywhere
(defvar user-temporary-file-directory "~/.emacs-backup")
(make-directory user-temporary-file-directory t)
(setq backup-by-copying t)
@PetrGlad
PetrGlad / git-line-status
Last active December 20, 2015 11:09
Code golfer's pet peeve
# lines diff
git diff --numstat | awk '{print($1 - $2, $3);}'
# how much lines added over time
git log --author=petr --shortstat --oneline | awk '/^ / {print($4 - $6);}' | awk '{sum += $1} END {print sum;}'
@PetrGlad
PetrGlad / gist:6235303
Created August 14, 2013 20:35
Android dev setup configuration
# to attach USB debugger see http://developer.android.com/tools/device.html
# to use GPU in emulator
ln -s /usr/lib/libGL.so.1 ~/android-sdk-linux_x86/tools/lib/libGL.so