Skip to content

Instantly share code, notes, and snippets.

Bookmarklet to switch between HackerNews and HackerWeb

This bookmarklet toggles between HackerNews pages and Cheeuan's HackerWeb interface. If you're not on either then it acts a a bookmark to HackerWeb.

The code

If you edit this, use something like bookmarkleter to convert it into a bookmarklet.

if ( /https?:\/\/news\.ycombinator\.com\/item\?id=(\d+)/.test(location) ) {

location = 'http://cheeaun.github.io/hackerweb/#/item/' + RegExp.$1;

@duncansmart
duncansmart / BackupEfsCerts.cs
Created March 28, 2013 23:22
Backup current user's EFS Certificates (including private keys)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
class CertDoodle
{
@duncansmart
duncansmart / progressive-ace.htm
Created March 28, 2013 23:29
Integrating ACE Editor in a progressive way
<textarea name="my-xml-editor" data-editor="xml" rows="15"></textarea>
...
<textarea name="my-markdown-editor" data-editor="markdown" rows="15"></textarea>
...
<script src="//d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js"></script>
<script>
// Hook up ACE editor to all textareas with data-editor attribute
$(function () {
@duncansmart
duncansmart / httpget.js
Created June 20, 2013 09:42
Download a file with Windows Script Host
// httpget.js: download a file (Windows Script Host)
// usage: cscript httpget.js <url> <file>
(function() {
if (WScript.Arguments.Length != 2) {
WScript.Echo("Usage: httpget.js <url> <file>")
WScript.Quit(1)
}
var url = WScript.Arguments(0)
@duncansmart
duncansmart / TransferToRouteResult.cs
Created June 27, 2013 12:20
MVC way to do Server.Transfer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace Foo.Bar
{
// Adpated from http://stackoverflow.com/questions/799511/how-to-simulate-server-transfer-in-asp-net-mvc
@duncansmart
duncansmart / CompileDataBinder.cs
Created August 1, 2013 11:10
A Reflection.Emit based version of DataBinder.Eval
using System;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
class Program
{
static void Main(string[] args)
{
Person model = new Person
@duncansmart
duncansmart / Custom Audit Events in ASP.NET.md
Last active December 22, 2015 06:09
Custom Audit Event

Custom Audit Class:

using System.Web.Management;
...
public class MyAuditEvent : WebAuditEvent
{
    public MyAuditEvent(string message, object eventSource, int eventCode)
        : base(message, eventSource,
               (eventCode < WebEventCodes.WebExtendedBase ? WebEventCodes.WebExtendedBase + eventCode : eventCode))

{

@duncansmart
duncansmart / EO-PDF-Forms.cs
Created October 8, 2013 22:46
Use EO.PDF to add form fieldst o a PDF
//File.WriteAllText(@"c:\temp\before.htm", html);
// Ensure all inputs have an ID
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.OptionWriteEmptyNodes = true;
htmlDoc.LoadHtml(html);
var srcInputs = htmlDoc.DocumentNode.SelectNodes("//input");
foreach (var item in srcInputs)
{
if (item.Id.Trim().Length == 0)
@duncansmart
duncansmart / select2-combo.js
Created October 17, 2013 16:14
Convert textbox to Select2 drop-down that allows new entries to be added (i.e. a combo box)
(function () {
var choices = [
"Foo",
"Bar",
"Baz"
];
$('#myTextBox')
.closest('.controls').append('<div class="help-block">Choose existing or type new one and press Enter</div>').end()
@duncansmart
duncansmart / PdfSplitAndMerge.cs
Created February 3, 2014 13:51
Split PDFs into PDF per page (which can then be edited by InkScape) and merge
static void pdfSplitIntoPages()
{
// EO.Pdf.Runtime.AddLicense("...");
string sourceFile = @"C:\TEMP\Blah.pdf";
var pdf = new PdfDocument(sourceFile);
var pages = pdf.Split(Enumerable.Range(1, pdf.Pages.Count-1).ToArray());
var i = 1;
foreach (PdfDocument page in pages)
{