Skip to content

Instantly share code, notes, and snippets.

View cbilson's full-sized avatar

Chris Bilson cbilson

View GitHub Profile
(defmacro when-let->
"Takes an expression and a set of binding+test/form pairs. Threads expr (via ->)
through each form for which the corresponding test
expression is true, binding the result of the test."
[expr & clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep (fn [[[res test] step]] `(if-let [~res ~test] (-> ~g ~step) ~g))]
`(let [~g ~expr
@cbilson
cbilson / gist:7601239
Last active December 29, 2015 02:29 — forked from halgari/gist:7002344
(defun nrepl-eval-expression-at-point-in-repl ()
(interactive)
(let ((form (nrepl-expression-at-point)))
;; Strip excess whitespace
(while (string-match "\\`\s+\\|\n+\\'" form)
(setq form (replace-match "" t t form)))
(set-buffer (cider-current-repl-buffer))
(goto-char (point-max))
(insert form)
(nrepl-return)))
(defun nrepl-eval-expression-at-point-in-repl ()
(interactive)
(let ((form (nrepl-expression-at-point)))
;; Strip excess whitespace
(while (string-match "\\`\s+\\|\n+\\'" form)
(setq form (replace-match "" t t form)))
(set-buffer "*nrepl*")
(goto-char (point-max))
(insert form)
(nrepl-return)))
@cbilson
cbilson / infoq.sh
Last active December 27, 2015 07:59 — forked from shirishp/infoq.sh
#! /bin/bash
# Original Author: Shirish Padalkar (https://twitter.com/_Garbage_)
if [ "$#" -ne 1 ]; then
echo "Usage: $0 infoq_presentation_url"
exit 1
fi
url_with_spaces=`curl -silent -A "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10" $1 | grep "<source src=" | tr -dc "[:print:]"`
@cbilson
cbilson / BulkInsert.cs
Created October 22, 2013 21:41
Example of sidestepping NHibernate to bulk insert a bunch of test records into the database. This is lame but it's fast.
public static class BulkInsert
{
private static SqlConnection Connection
{
get { return NHibernateSession.NHibernateSessionManager.Instance.GetSession().Connection as SqlConnection; }
}
public static void Meters(IEnumerable<EisMeter> meters)
{
@cbilson
cbilson / DatabaseSnapshot.cs
Last active December 26, 2015 06:29
Creates a database snapshot and then restores the database when it's disposed.
public class DatabaseSnapshot: IDisposable
{
private readonly SqlConnection connection;
private readonly string database;
private bool disposed;
public DatabaseSnapshot()
: this(NHibernateSession.NHibernateSessionManager.Instance.GetStatelessSession().Connection as SqlConnection)
{}
@cbilson
cbilson / SerializingAutoProperties.cs
Created September 24, 2013 15:02
All of these assertions pass.
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
namespace ClassLibrary1
{
[Serializable]
@cbilson
cbilson / Profile.ps1
Last active June 6, 2023 09:20
Current Profile. Contains a few TFS hacks...for if I ever need to use TFS again.
Set-StrictMode -version Latest
function Test-FileDep($a,$b) {
$bExists = test-path $b
$aTs = (Get-Item $a).LastWriteTime
return $bExists -and $aTs -le (Get-Item $b).LastWriteTime
}
function Update-Path($val) {
function New-SqlServerAlias($name, $server='.', $protocol='tcp', $port='1433') {
$options = New-Object System.Management.ConnectionOptions
$options.Context.Add('__ProviderArchitecture', 64)
$path = '\\.\root\microsoft\sqlserver\computermanagement11'
$scope = New-Object System.Management.ManagementScope($path, $options)
$scope.Connect()
$managementPath = New-Object System.Management.ManagementPath('SqlServerAlias')
$class = New-Object System.Management.ManagementClass($scope, $managementPath, $null)
@cbilson
cbilson / gist:5935906
Created July 5, 2013 17:09
TFS link type for org-mode
(defvar *tfs-server* "http://hqvm32:8080")
(defvar *tfs-root* "/tfs/Calico/EIS")
(defun org-open-tfs (item)
(browse-url (concat *tfs-server* *tfs-root* "/_workItems#_a=edit&id=" item)))
(org-add-link-type "tfs" 'org-open-tfs)