Skip to content

Instantly share code, notes, and snippets.

View flengyel's full-sized avatar
🎯
Focusing

F Lengyel flengyel

🎯
Focusing
  • The City University of New York, retired
  • New York
  • 01:39 (UTC -04:00)
View GitHub Profile
@flengyel
flengyel / onrender.html
Created August 7, 2013 16:16
Worked examples derived from Chapter 2 of Building Backbone Plugins.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta lang="en">
<title>Backbone BaseView with corrections</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="backbone.js"></script>
</HEAD>
<BODY>
@flengyel
flengyel / baseview.html
Last active December 20, 2015 15:49
Elaboration on and corrections to the BaseView object from Building Backbone Plugins. The main correction is the substitution of item.message for item in the underscore template for the CollectionView constructor. This is no criticism: the book is refreshingly to the point--the authors know their audience.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<meta lang="en">
<title>Backbone BaseView with corrections</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="underscore.js"></script>
<script type="text/javascript" src="backbone.js"></script>
</HEAD>
<BODY>
@flengyel
flengyel / boxunion.py
Created November 19, 2012 04:25
Unions of polygonal boxes in GDAL
#!/usr/bin/python
from __future__ import division
from numpy import *
from osgeo import ogr
def box(scale, offset):
sample = offset + array([[-1,-1],[-1,1],[1,1],[1,-1]])
sample = scale * sample
ring = ogr.Geometry(ogr.wkbLinearRing) # create Polygon geometry
@flengyel
flengyel / pictures.markdown
Created August 30, 2012 03:49 — forked from sent-hil/pictures.markdown
River (getriver.com): Keep a programming journal.

One of my favorite past times is to look at the notebooks of famous scientists. Da Vinci's notebook is well known, but there plenty others. Worshipping Da Vinci like no other, I bought a Think/Create/Record journal, used it mostly to keep jot down random thoughts and take notes. This was great in the beginning, but the conformity of lines drove me nuts. Only moleskines made blank notebooks, so I had to buy one.

At the same time I started a freelance project. The project itself is irrelevant, but suffice to say it was very complex and spanned several months. It seemed like a perfect opportunity to use the moleskine. Looking back, all my entries fell under few categories:

  • Todo
  • Question
  • Thought
  • Bug
  • Feature
;; flengyel's solution to Game of Life
;; https://4clojure.com/problem/94
(fn [board]
(letfn [ (remap [board]
(->> (for [v board]
(->> (map (fn [c] (if (= (str c) " ") 0 1)) v)
(apply vector)))
(apply vector)))
(unmap [matrix]
@flengyel
flengyel / insort.clj
Created December 9, 2011 05:33
Insetion sort in clojure
(def v (shuffle (range 10)))
(defn swap-down [v i]
(loop [j i w v]
(if (> j 0)
(let [a (nth w (dec j)) b (nth w j)]
(if (> a b)
(recur (dec j) (assoc w (dec j) b j a))
w))
w)))
;; flengyel's solution to Sum Some Set Subsets
;; https://4clojure.com/problem/131
(fn [s & ss]
(letfn [
(subsets [s]
(if (empty? s)
#{#{}}
(let [x (set (list (first s)))
dx (clojure.set/difference s x)
;; flengyel's solution to Power Set
;; https://4clojure.com/problem/85
(fn power [s]
(if (empty? s)
#{#{}}
(let [x (set (list (first s)))
dx (clojure.set/difference s x)
t (power dx)]
(clojure.set/union t
;; flengyel's solution to Juxtaposition
;; https://4clojure.com/problem/59
(fn [x & xs]
(fn [y & ys] (vec (for [f (vec (concat [x] xs))] (apply f (vec (concat [y] ys)))))))
;; flengyel's solution to Sequs Horribilis
;; https://4clojure.com/problem/112
(fn [n s]
(letfn [(sequs [n s]
(loop [acc 0 v [] s s]
(if (or (empty? s) (< n acc))
[acc v]
(let [elt (first s)]
(if (vector? elt)