Skip to content

Instantly share code, notes, and snippets.

public class Exercises {
public static void main(String[] args) {
/*
1. 4 birds are sitting on a branch. 1 flies away. How many birds are left on
the branch?
*/
/*
@firstclown
firstclown / KeepCentered.py
Created March 11, 2014 19:38
Keep view centered on caret (a la Scrivener) when in distraction free mode. Needs the awesome FullScreenStatus plugin.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import re
import sublime
import sublime_plugin
class KeepCentered(sublime_plugin.EventListener):
def on_modified_async(self, view):
function generateRandomString($length = 15)
{
return substr(sha1(rand()), 0, $length);
}
@firstclown
firstclown / plugin.php
Created January 21, 2014 13:45
YOURLS plugin to show user agent data on traffic location tab in admin.
<?php
/*
Plugin Name: User Agents
Plugin URI: https://gist.github.com/firstclown/
Description: Shows User Agents on the Traffic Location page
Version: 1.0
Author: firstclown
Author URI: http://www.jerickson.net/
*/
@firstclown
firstclown / insertAtCaret.js
Created January 15, 2014 15:32
Add a new jQuery function that will allow you to add text to the current caret position in textarea and text fields. Pulled from some Stack Overflow question.
jQuery.fn.extend({
insertAtCaret: function(myValue){
return this.each(function(i) {
if (document.selection) {
//For browsers like Internet Explorer
this.focus();
var sel = document.selection.createRange();
sel.text = myValue;
this.focus();
}
@firstclown
firstclown / plainTextToHTML.js
Created January 15, 2014 15:28
Convert plain text in message variable to properly formatted HTML
message.replace(/\n([ \t]*\n)+/g, '</p><p>').replace(/\n/g, '<br />');
@firstclown
firstclown / sl.fish
Created January 4, 2014 19:39
Starts Sublime Text using the passed in file/folder or, if nothing is passed in, using the current folder.
function sl
if test (count $argv) -eq 0
set argv[1] '.'
end
subl -n $argv
end
@firstclown
firstclown / generate_book.fish
Created January 4, 2014 17:31
Take a markdown file in a blown out ePub and generate a .mobi and .epub ebook from it. ebook-convert is a Calibre command line app.
function generate_book
multimarkdown $argv[1].md -o story.html
kindlegen assembly.opf -o $argv[1].mobi
ebook-convert $argv[1].mobi $argv[1].epub --page-breaks-before=/
end
@firstclown
firstclown / fillin.rb
Created December 31, 2013 00:58
Wanted an easy way to take a directory, copy it, and then fill in all the files within it with custom values.
#!/usr/bin/env ruby
require 'optparse'
require 'securerandom'
require 'fileutils'
require 'erb'
params = {}
target_directory = "New"
# Parse args
var id = Math.random().toString(16).slice(2)