Skip to content

Instantly share code, notes, and snippets.

View lee-dohm's full-sized avatar
😴
Taking some well-deserved naps

Lee Dohm lee-dohm

😴
Taking some well-deserved naps
View GitHub Profile
var exec = require('child_process').spawn;
var node = exec('node', process.argv.splice(2), {stdio: 'inherit'});
@lee-dohm
lee-dohm / count_bits.c
Created September 1, 2014 01:02
Code for blog entry: "Interview Question Pitfalls"
long count_bits(long number) {
// Accumulates the total bits set in `number`
unsigned int count;
// This loop initializes the count, loops only until all bits have been cleared and
// increments the count each time through the loop.
for (count = 0; number; count++) {
// Clear the least significant bit set
number &= number - 1;
}
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z]+\.)*([A-Za-z]+)( extends [A-Za-z.]+)?$/\3/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z.]+):.*[-=]>.*$/\3/m,method/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--regex-coffee=/^[ \t]*@([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/f,field/
--regex-coffee=/^[ \t]*@([A-Za-z.]+):[^->\n]*$/\1/f,static field/
--regex-coffee=/^[ \t]*([A-Za-z.]+):[^->\n]*$/\1/f,field/
--regex-coffee=/(constructor: \()@([A-Za-z.]+)/\2/f,field/
@lee-dohm
lee-dohm / snippets.cson
Created January 28, 2015 12:00
Multi-line Snippets
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
@lee-dohm
lee-dohm / count-modules
Last active August 29, 2015 14:15
Count Atom package dependencies
#!/usr/bin/env ruby
require 'json'
require 'set'
package_dir = "#{ENV['HOME']}/.atom/packages"
packages = Dir[File.join(package_dir, '*')].select { |file| File.directory?(file) }
dependencies = {}
packages.each do |package|
@lee-dohm
lee-dohm / gist:a7999434b3faf2c124ec
Created March 6, 2015 02:32
Java Random for Rock, Paper, Scissors, Lizard, Spock
import java.util.Random;
Random random = new Random();
int number = random.nextInt(5); // Rock = 0, Paper = 1, Scissors = 2, Lizard = 3, Spock = 4
@lee-dohm
lee-dohm / gist:4081aed9033107ac5d33
Last active August 29, 2015 14:20
Deprecation Cleanup Checklist

Deprecation Cleanup Checklist

Packages

  • tabs-to-spaces — 22,223
  • auto-copyright — 1,148
  • file-type-icons — 5,394
  • set-syntax — 3,912
  • language-r — 3,307
  • indentation-indicator — 1,269
@lee-dohm
lee-dohm / gist:5d7d23cdd024fd5f1f46
Last active August 29, 2015 14:23
Code Convention Guidelines System

The guidelines will follow the convention described in Microsoft's .NET Framework Design Guidelines:

The guidelines are organized as simple recommendations using DO, CONSIDER, AVOID, and DO NOT. For example, a Do guideline is one that should virtually always be followed. On the other hand, Consider guidelines should generally be followed, but if you fully understand the reasoning behind a guideline and have a good reason to not follow it anyway, you should not feel bad about breaking the rules. Similarly, Do not guidelines indicate something you should almost never do. Less strong, Avoid guidelines indicate that something is generally not a good idea, but there are known cases where breaking the rule makes sense.

Some more complex guidelines are followed by additional background information, illustrative code samples, and rationale.

'.source.java':
'private static final':
prefix: 'psf'
body: 'private static final'
'private static final String':
prefix: 'psfs'
body: 'private static final String'
'JUnit Test':
prefix: 'test'
body: """