Skip to content

Instantly share code, notes, and snippets.

View daGrevis's full-sized avatar
⌨️
Keyboard operator

Raitis Stengrevics daGrevis

⌨️
Keyboard operator
View GitHub Profile
@daGrevis
daGrevis / quicksort.clj
Last active August 29, 2015 13:56
Quicksort in Clojure
(defn pivot-and-rest [coll]
(let [splitted (split-at (quot (count coll) 2) coll)
second-part (second splitted)]
[(first second-part) (concat (first splitted) (rest second-part))]))
(defn quicksort [coll]
(cond
(empty? coll) []
(= (count coll) 1) coll
:else (let [[p xs] (pivot-and-rest coll)
@daGrevis
daGrevis / url.regex
Last active August 29, 2015 13:57
Will match 99% URLs
/
(?:(\w+)\:?\/\/)? # Protocol
([^\/?]+) # Optional subdomains, domain and TLD
\/? # Traling slash
([^\?]*) # Path
([^\#]*) # Query
(\#?.*) # Fragment
/xu
# http://regex101.com/r/oV5tN9

Everything is pip 1.4+ all downloads starting 2014-01-02 and ending with 2014-04-13.

SELECT python_type, array_to_string(python_release[0:2], '.') AS python_release, COUNT(*)
FROM (
    SELECT
        python_type,
        string_to_array(
            (
                CASE WHEN (python_release IS NULL OR python_release = '')
@defndaines
defndaines / fizz-buzz.clj
Last active August 29, 2015 14:09
Unconditional Fizz Buzz
; Inspired by https://twitter.com/gigasquid/status/530699466891067392 ...
; An implementation of the Fizz Buzz Kata with no conditionals.
(defn fb-gen
[step value]
(into (sorted-map) (zipmap (range step 101 step) (repeat value))))
(def nums (into (sorted-map) (zipmap (range 1 101) (range 1 101))))
(def threes (fb-gen 3 "fizz"))
(def fives (fb-gen 5 "buzz"))
(def fifteens (fb-gen 15 "fizzbuzz"))
@franks42
franks42 / cljs_uuidv4.cljs
Created November 28, 2012 06:34
UUID generation algorithm for a v4/random UUID
(ns cljs-uuidv4
"Generator for a v4/random UUID that works with cljs.core/UUID"
(:require [goog.string.StringBuffer]))
(defn UUIDv4
"Returns a new randomly generated (version 4) cljs.core/UUID,
like: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
as per http://www.ietf.org/rfc/rfc4122.txt.
Usage:
(defmacro makexml [code]
(import [hy.models.expression [HyExpression]]
[hy.models.dict [HyDict]])
(defn dict-to-attrs [d]
(setv keys (slice d 0 (len d) 2))
(setv vals (slice d 1 (len d) 2))
(.join " " (list-comp
(kwapply
(.format "{name}=\"{value}\"")
{"name" i "value" (get vals (.index keys i))})
@daGrevis
daGrevis / gist:1389650
Created November 23, 2011 19:32
Fibonacci sequence in Python 2.7 (almost 1st script in Python)
def fibonacci(n):
result = []
x, y = 0, 1
while x < n:
result.append(x)
x, y = y, y + x
@aseemk
aseemk / coffeescript-updates.md
Last active December 2, 2017 20:22
CoffeeScript upcoming changes.

CoffeeScript 1.7 is shaping up to be a pretty kick-ass release with significant improvements. Here are the ones I'm most excited about, in order of my own excitement.

Parentheses-free chaining

jashkenas/coffeescript#3263

Years of being wished for, finally granted!

@nealtodd
nealtodd / settings_test_snippet.py
Last active November 14, 2019 01:25
Skip migrations for a Django 1.7 test run
# If your test settings file doesn't import any other settings file
# then you can use the function directly:
def prevent_tests_migrate(db):
import django
from django.db import connections
from django.db.migrations.executor import MigrationExecutor
django.setup()
ma = MigrationExecutor(connections[db]).loader.migrated_apps
return dict(zip(ma, ['{a}.notmigrations'.format(a=a) for a in ma]))
@arbelt
arbelt / init.lua
Created October 2, 2016 20:55
Hammerspoon config to send escape on short ctrl press
ctrl_table = {
sends_escape = true,
last_mods = {}
}
control_key_timer = hs.timer.delayed.new(0.15, function()
ctrl_table["send_escape"] = false
-- log.i("timer fired")
-- control_key_timer:stop()
end