Skip to content

Instantly share code, notes, and snippets.

View joncol's full-sized avatar

Jonas Collberg joncol

View GitHub Profile
@scvalex
scvalex / Warshall.hs
Created May 4, 2010 21:00
Floyd-Warshall in 2 lines of Haskell
module Warshall where
import Data.Char ( isAlpha )
import Data.List ( nub, sort )
import System.Environment ( getArgs )
import Text.Parsec
import Text.Parsec.String
import Text.Printf ( printf )
type Vertex a = a
@andref
andref / main.cpp
Created May 30, 2012 19:47
Calling QMetaMethods with QVariant arguments and best-effort type conversion
#include <QtCore>
#include <QtDebug>
QVariant call(QObject* object, QMetaMethod metaMethod, QVariantList args)
{
// Convert the arguments
QVariantList converted;
// We need enough arguments to perform the conversion.
@sedm0784
sedm0784 / CapsLockCtrlEscape.ahk
Last active April 11, 2025 12:38
AutoHotkey script to map Caps Lock to Escape when it's pressed on its own and Ctrl when used in combination with another key, à la Steve Losh. Adapted from one that does something similar with the Ctrl Key on the Vim Tips Wiki (http://vim.wikia.com/wiki/Map_caps_lock_to_escape_in_Windows?oldid=32281). (Plus contribs from @randy909 & @mmikeww.)
g_LastCtrlKeyDownTime := 0
g_AbortSendEsc := false
g_ControlRepeatDetected := false
*CapsLock::
if (g_ControlRepeatDetected)
{
return
}
@prwhite
prwhite / Makefile
Last active April 19, 2025 09:46
Add a help target to a Makefile that will allow all targets to be self documenting
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
# Everything below is an example
target00: ## This message will show up when typing 'make help'
@echo does nothing
@kidpollo
kidpollo / app-server.clj
Created March 29, 2014 06:37
Example compojure app using stuartsierra/component
(ns app.api-server
(:require [compojure.core :as compojure]
[com.stuartsierra.component :as component]
[app.app :as app]
[ring.adapter.jetty :as jetty]))
(compojure/defroutes app
app/handler)
(defrecord AppServer [port server]
@jcouyang
jcouyang / stop-asking.el
Last active June 29, 2020 14:01
disable emacs asking following git symbolink
; 当要打开一个symbolink的时候,如果symbollink到一个被git(或者其他vc)管理的文件时,emacs老问
; Symbolic link to Git-controlled source file; follow link? (y or n)
; 配置下这个变量就好了
(setq vc-follow-symlinks nil)
; nil 表示 不要问,no
; ask 表示每次都问
; t 表示follow
@carcinocron
carcinocron / debugger pause beforeunload
Last active April 28, 2025 12:59
Chrome: pause before redirect
// Run this in the F12 javascript console in chrome
// if a redirect happens, the page will pause
// this helps because chrome's network tab's
// "preserve log" seems to technically preserve the log
// but you can't actually LOOK at it...
// also the "replay xhr" feature does not work after reload
// even if you "preserve log".
window.addEventListener("beforeunload", function() { debugger; }, false)
@dmgottlieb
dmgottlieb / gist:56369e01521c61dd00b6
Created July 15, 2015 18:43
4-tower Tower of Hanoi solutions using μ-recursion in Haskell
import Data.List
import Data.Ord
-- Tower of Hanoi implementation
type Peg = String
type Move = (Peg, Peg)
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
hanoi 0 a b c = [ ]
hanoi n a b c = hanoi (n-1) a c b ++ [(a,b)] ++ hanoi (n-1) c b a
@halberom
halberom / opt1_template.j2
Last active January 17, 2025 12:34
ansible - example of template if else
{# style 1 - long form #}
{% if filepath == '/var/opt/tomcat_1' %}
{% set tomcat_value = tomcat_1_value %}
{% else %}
{% set tomcat_value = tomcat_2_value %}
{% endif %}
{# style 2 - short form #}
{% set tomcat_value = tomcat_1_value if (filepath == '/var/opt/tomcat_1') else tomcat_2_value %}