Posts

  • After years of searching finally found a holy grail to fix iterm2 clipboard

    To enable this:

    Go into iTerm2’s preferences.

    Go to the “General” tab.

    Check “Applications in terminal may access clipboard”

    Done

  • Sorting js imports on file save emacs

    Sorts your js imports by assigning weights

      (defun sort-js-imports ()
    (interactive)
    (sort-js-imports-region nil (point-min) (get-end-of-js-import))
    )

    (defun get-end-of-js-import ()
    (save-excursion
    (goto-char (point-max))
    (search-backward-regexp "import")
    (word-search-forward "from" nil t)
    (line-end-position)
    )
    )

    (defun sort-js-imports-region (reverse beg end)
    (interactive "P\nr")
    (save-excursion
    (save-restriction
    (narrow-to-region beg end)
    (goto-char (point-min))
    (let ;; To make `end-of-line' and etc. to ignore fields.
    ((inhibit-field-text-motion t))
    (sort-subr reverse
    'forward-line
    (lambda () (search-forward "from" nil t) (end-of-line))
    (lambda ()
    (let (
    (skip-amount (save-excursion (search-forward "from" nil t)))
    (skip-amount-end (line-end-position))
    )
    (cons skip-amount skip-amount-end)
    )
    )
    nil
    (lambda (a b)
    (let ((s1 (buffer-substring (car a) (cdr a)))
    (s2 (buffer-substring (car b) (cdr b))))
    (message (format "[%s] [%s] [%s] [%s] [%s]\n" s1 s2 a b (calculate-string-priority s1 s2)))
    (calculate-string-priority s1 s2)
    )
    ))))))

    (defun calculate-string-priority (s1 s2)
    (< (+ (calculate-js-import-priority s1) (if (string< s1 s2) -1 1)) (calculate-js-import-priority s2)))

    (defun calculate-js-import-priority (import)
    (catch 'val
    (cond
    ((> (or (string-match "lodash" import) -2) -1) (throw 'val 0))
    ((> (or (string-match "'react'" import) -2) -1) (throw 'val 10))
    ((> (or (string-match "/constants/" import) -2) -1) (throw 'val 30))
    ((> (or (string-match "/actions/" import) -2) -1) (throw 'val 40))
    ((> (or (string-match "/components/" import) -2) -1) (throw 'val 50))
    ((> (or (string-match "/containers/" import) -2) -1) (throw 'val 60))
    ((> (or (string-match "/services/" import) -2) -1) (throw 'val 70))
    ((> (or (string-match "/selectors/" import) -2) -1) (throw 'val 80))
    ((> (or (string-match "/hoc/" import) -2) -1) (throw 'val 90))
    ((> (or (string-match "scss" import) -2) -1) (throw 'val 100))
    ((> (or (string-match "../" import) -2) -1) (throw 'val 110))
    (t (throw 'val 20)))
    )
    )

    (add-hook 'js-mode-hook
    (lambda () (add-hook 'before-save-hook #'sort-js-imports nil 'local)))
  • While wallaby is not support emacs or vim, here is a temp solution with mocha

    I am using spacemacs http://spacemacs.org/ You will need to install mocha package and add this config to your .spacemacs config or adjust code to whatever you are using. Basically it switches to a test file and executes tests in that file when you click SPC+m+T

      (require 'projectile)
    (defun atz-exec-if-in-spec-or-switch-and-then-exec (cmd)
    (let ((current-file-name (file-name-nondirectory (buffer-file-name))))
    (if (string-match "spec" current-file-name)
    (funcall cmd)
    (projectile-toggle-between-implementation-and-test)
    (funcall cmd)
    )
    )
    )

    (with-eval-after-load 'js2-mode
    (evil-leader/set-key "mT"
    '(lambda()
    (interactive)
    (atz-exec-if-in-spec-or-switch-and-then-exec 'mocha-test-file)
    )
    )
    )
  • iPhone safari has a bug when using fixed element in overflow div while in an iframe

    Moving fixed element out of the overflow: scroll div fixes erratic behaviour

    We had 2 elements which had fixed positioning.

      <iframe>
    ...
    <div class="scrollable">
    <div class="fixed">
    </div>
    </div>
    ...
    </iframe>

    And while scrolling those elements where jumping eratically. And that only happened if your widget was in a scrolling iframe. The solution was quite simple, move the fixed element out of scrollable div!

      <iframe>
    ...
    <div class="scrollable">
    </div>
    <div class="fixed">
    </div>
    ...
    </iframe>

    One of elements had to be inside the scrollable div, because it was part of a bigger component in React and I did not want to put it outside. This was solved easily with a Gateway/Portal https://github.com/cloudflare/react-gateway

  • Clojure meetup in Vilnius

    Vilnius Clojure #10

    Gorilla REPL (Jonas Jarutis)

    • intro to Gorilla REPL (http://gorilla-repl.org)
    • demo of features like plotting graphs and rich editing
    • play with some data analysis and visualization

    tools.namespace (Osvaldas Grigas)

    • the pains of reloading namespaces with plain REPL
    • tools.namespace to the rescue
    • Stuart Sierra’s Clojure workflow, Reloaded

    @Vinted HQ

    more info: http://www.meetup.com/Vilnius-Clojure/events/225554208/

  • Clojure json and array map

    In clojure you can have 3 different key types (as far as i have encountered them)

    Keyword keys

    { :keyword "value" }

    Unevaluated form

    { 'unevaluated "value" }

    String

    { "string" "value" }

    As I did not know about string keys I was stuck with ring.middleware.json/wrap-json-response because whenever i tried to

    (get { "string" "value" } :string)
    (get { "string" "value" } 'string)

    It yield no result… And in repl you would see this map represnted as

    { string value }

    It does not matther whether you evaluate string key or unevaluated form key

    { 'string value }
    { "string" value }

    So that was the reason why it was so confusing

    Anyway problem was solved by doing

    (get { "string" "value" } "string")

    Although I think, maybe it would be better to make keywords from string keys by calling clojure.walk/keywordize-keys

    (:string (clojure.walk/keywordize-keys { "string" "value" }))

    ?

  • Testing clojure post json request

    I am working on side project, and I’ve decided to use clojure for backend, although was planning to use ruby before.

    So I was stuck with testing json request as I was planning to test everything that is possible. Here is how I managed to make a POST request with json. Posting it here because I couldn’t find any info on the nets at the point of writing

    the test:

      (:require [clojure.test :refer :all]
    [ring.mock.request :as mock]
    [clojure.data.json :as json]
    [YOUR.NAMESPACE.HERE :refer :all]))

    (deftest first-test
    (testing "settings endpoint"
    (let [response
    (application
    (mock/content-type (mock/body
    (mock/request :post "/votes")
    (json/write-str { :vote "test" }))
    "application/json"
    ))]
    (is (= (:status response) 200))
    (is (= (get-in response [:body]) "{\"my-map\":\"test\"}"))
    (is (= (get-in response [:headers "Content-Type"]) "application/json; charset=utf-8")))

    application routes:

      ;[ring.middleware.json :as middleware]

    (def application
    (middleware/wrap-json-response (middleware/wrap-json-body
    routes)))

    controller:

      ;(:require [compojure.core :refer [defroutes GET POST]]
    ; [clojure.string :as str]
    ; [ring.util.request :as request]
    (defn putBack
    [request]
    {:body {:my-map (get-in request [:body "vote"])}})

    (defroutes routes
    (POST "/votes" request (putBack request))
  • DIY hologram with a phone

    It is so fascinating to see stuff flying, we are human beings that dream about it. And holograms have the power to fly (sort of). I stumbled on this video, and it will be my next small project.

    This time, here is a video instead of text. Enjoy:

  • Vimium for Google Chrome

    You know, all those scary stories about carpal tuner syndrome. Yep they got me. And also using mouse is so slow. And you have to remove your hands from the keyboard. Which is annoying.

    So while I was still a .NET developer I was coding with Visual Studio and vim add-on. When I moved to pure front-end and got my first Mac I move to terminal and vim (trying to get emacs at the moment). So everything is great except… Browsers… Yep… They requires a lot of mouse, even though Mac Magic Trackpad you still have to move your hands. Anyway after some research I found out about Vimium And it is simply amazing…

    Try it.

    P.s. gaming with only keyboard or trackpad still sucks…

  • Rage on Asus

    One of my dreams was to write a blog. However every time, once I registered on a blogging platform, created a blog and closed it. I’ve never opened it again. I tried starting for like 7 times now. So here I am after 7 years creating a blog which should be about technology, development actually, probably front end development… And I’m writing about Asus. Ahhhh… dear nice Asus, a great company, making great laptops. I really liked it. If you dear reader are interested in it - it was Asus u36sd. I bought one for myself and my gf.

    ##The story of my Asus u36sd

    • audio jacket cracked
    • battery cracked

    Both still kind of worked so its ok And just few weeks before warranty was over HDD died… Anyways they just changed it and it worked well. Bought it for 870 Euros after 4 years sold it for 200 Euros.

    ##The story of my gf’s Asus

    Everything as fine except battery cracking, and that she broke the outer part of the screen.

    Well few days ago it happened. She stepped onto her laptop, while charger head was still inside. Result? Screen cracked into half. She was very sad, because it would cost 300euro just to fix the screen.

    So here come I.

    • I am an Engineer! - I say. I found video in youtube how to replace screen in Asus, and said:
    • I will find screen on ebay, and replace it myself.

    I found it, 50dollars for the screen - cool. Got it in a week and started taking notebook apart. I took the LCD, the process was a bit different than in video, but I managed to do that. Great success. Then I I checked the connectors and OH… One of connectors is different. What??? Why??? Its the same Asus u36sd laptop and I bought Asus u36sd screen… And then I see it… On the screen in the inner part of laptop they wrote model of this Asus. Asus U36JC…

    Yep… The computer, the main frame is Asus u36sd… and the screen is u36jc… Why???

    So… we now have a pc with no LCD…

    Screw asus, apple rules!

    P.s. every time I tried to create a blog it was on asus.

subscribe via RSS