Skip to content

Instantly share code, notes, and snippets.

require 'digest/md5'
def gfm(text)
# Extract pre blocks
extractions = {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
extractions[md5] = match
"{gfm-extraction-#{md5}}"
end
@dauger
dauger / IListOfTExtensions.cs
Created January 19, 2011 21:37
Extension method to determine if a list is ordered asc
public static class IListOfTExtensions
{
public static bool IsOrdered<T, T2>(this IList<T> @this, Func<T, T2> orderedOnProperty)
where T2 : IComparable<T2>
{
var isLessThanOrEqualTo = true;
for (int i = 1; i < @this.Count; i++)
{
var comparer = Comparer<T2>.Default;
@ismasan
ismasan / phantom_js_url_cycle.js
Created May 15, 2011 15:24
Super easy web screen scraping with Phantom.js. Screenshots example.
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Cycle array of URLs and process with phantom.js (http://www.phantomjs.org/)
Adds Array.prototype.forEachWebPage() iterator.
EXAMPLE:
Save screenshots. Command line:
phantomjs phantom_js_url_cycle.js ./screenshots
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[
@jakejscott
jakejscott / MongoCache.cs
Created October 5, 2011 15:01
Lightspeed ORM second level cache using MongoDB (Doesn't support expirying items yet..todo)
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Loot.Logging;
using Mindscape.LightSpeed.Caching;
using MongoDB.Driver;
using MongoDB.Driver.Builders;
namespace Loot
{
@alanstevens
alanstevens / newgemset.sh
Last active September 28, 2015 21:39
A shell script for creating a new gemset. The default gemset name is the current working directory but there is an optional parameter for creating a custom gemset name
#!/usr/bin/env bash
readonly rubyversion="1.9.3"
# Source RVM as a function into local environment.
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
@wcharczuk
wcharczuk / numpy.cs
Created October 24, 2012 20:20
Implementation of LogSpace and LinSpace from Numpy for C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace libSVM
{
public static class Numpy
{
public static IEnumerable<double> Arange(double start, int count)
@kvnsmth
kvnsmth / example-subtree-usage.md
Last active March 24, 2025 17:21
A real world usage for git subtrees.

Let's say you have an iOS project, and you want to use some external library, like AFNetworking. How do you integrate it?

With submodules

Add the project to your repo:

git submodule add [email protected]:AFNetworking/AFNetworking.git Vendor/AFNetworking

or something to that effect.

@mletterle
mletterle / git-tfs rcheckin prepare-commit-msg hook
Last active December 27, 2015 14:39
Handy little hook I think...
#!/bin/bash
branchname=`git symbolic-ref -q --short HEAD`
if [[ $branchname =~ 'tfs-.*' ]]; then
workitems=$(echo $branchname | sed s/tfs-//g | tr ',' ' ' )
for workitem in $workitems;
do
cp $1 $1.old
$(sed '1s/^/#git-tfs-work-item: '$workitem' associate\n/' $1.old > $1)
@idosela
idosela / http-response-interceptor.js
Last active February 25, 2024 12:51
Sample code for ng-conf 2014
angular.module('myMdl', []).config(['$httpProvider', function($httpProvider) {
$httpProvider.responseInterceptors.push([
'$q', '$templateCache', 'activeProfile',
function($q, $templateCache, activeProfile) {
// Keep track which HTML templates have already been modified.
var modifiedTemplates = {};
// Tests if there are any keep/omit attributes.
var HAS_FLAGS_EXP = /data-(keep|omit)/;
// kills long running ops in MongoDB (taking seconds as an arg to define "long")
// attempts to be a bit safer than killing all by excluding replication related operations
// and only targeting queries as opposed to commands etc.
killLongRunningOps = function(maxSecsRunning) {
currOp = db.currentOp();
for (oper in currOp.inprog) {
op = currOp.inprog[oper-0];
if (op.secs_running > maxSecsRunning && op.op == "query" && !op.ns.startsWith("local")) {
print("Killing opId: " + op.opid