Skip to content

Instantly share code, notes, and snippets.

@lowjoel
lowjoel / with_temporary_table.rb
Last active Aug 29, 2015
RSpec test group helpers for creating tables.
View with_temporary_table.rb
# Test group helpers for creating tables.
# The latest version can be gound at https://gist.github.com/lowjoel/bda0d44b48aac2925079
module ActiveRecord::TemporaryTable; end
module ActiveRecord::TemporaryTable::TestGroupHelpers
# Defines a temporary table that is instantiated when needed, within a `with_temporary_table`
# block.
#
# @param [Symbol] table_name The name of the table to define.
# @param [Proc] proc The table definition, same as that of a block given to
# +ActiveRecord::Migration::create_table+
@lowjoel
lowjoel / coverage_helper.rb
Last active Jan 30, 2017
Simultaneous Code Coverage Reporting to Coveralls and Code Climate
View coverage_helper.rb
# frozen_string_literal: true
# Simultaneous code coverage reporting to Coveralls and Code Climate.
# Latest version can be found at https://gist.github.com/lowjoel/6c2f2d3a08bb3786994f
require 'simplecov'
module CoverageHelper
class << self
# Helper to include Coveralls/Code Climate coverage, but not require developers to install the
# gem.
#
View bundle_gem_libs.rb
# This script is to work round the problem of broken RubyMine dependencies for bundle files.
# It uses an undocumented feature for RubyMine (but available in Intellij Idea) to create a
# gems library xml file and update the iml file.
#
# See Rubymine issues:
# https://youtrack.jetbrains.com/issue/RUBY-16428
# https://youtrack.jetbrains.com/issue/RUBY-15026
# https://youtrack.jetbrains.com/issue/RUBY-14542
#
# Usage:
@lowjoel
lowjoel / MatrixMultiply.x10
Created Mar 25, 2015
Matrix Multiplication in x10
View MatrixMultiply.x10
import x10.io.Console;
public class MatrixMultiply {
private interface Matrix[T] {
public def initial(): T;
public def width(): Long;
public def widthRange(): LongRange;
public def height(): Long;
public def heightRange(): LongRange;
@lowjoel
lowjoel / elliptic_curve.rb
Last active Aug 29, 2015
elliptic_curve.rb
View elliptic_curve.rb
class Point
def initialize(x, y)
@x = x
@y = y
end
def to_s
"(#{@x}, #{@y})"
end
@lowjoel
lowjoel / cpplint.py
Last active Aug 29, 2015
cpplint.py, fixed for Windows
View cpplint.py
#!/usr/bin/python
#
# Copyright (c) 2009 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
@lowjoel
lowjoel / sleepbot-migrate-to-sleep_as_android.rb
Last active Jul 13, 2019
Migrates SleepBot data to Sleep as Android's format
View sleepbot-migrate-to-sleep_as_android.rb
require 'csv'
# Parses CSV-exported data from SleepBot
def parse_export(row)
# Parse the wake up date
date_to = row[0].split('/')
date_to = Time.new(2000 + date_to[2].to_i, date_to[1], date_to[0])
# Parse the wake up/sleep times
time_from = row[1].split(':')
@lowjoel
lowjoel / rubocop.sh
Last active Aug 29, 2015
Running Rubocop from the Command Line, generating a JUnit report
View rubocop.sh
#!/usr/bin/env ruby2.1
# Modified from
# https://github.com/clintoncwolfe/chef-ci-tools/blob/master/bin/rubocop-junit-tee.rb
require 'fileutils'
# This first part runs Rubocop proper
puts "Executing within: #{Dir.pwd}"
RUBOCOP_XML = ARGV.shift
RUBOCOP_JSON = "#{RUBOCOP_XML}.json"
RUBOCOP = 'rubocop -R'
@lowjoel
lowjoel / jshint.sh
Last active Aug 29, 2015
Running JSHint from the command line without rake
View jshint.sh
#!/usr/bin/env ruby
# encoding: utf-8
require 'jshint'
require 'jshint/reporters'
reporter_name = ARGV[0] || :Default
file = ARGV[1]
linter = Jshint::Lint.new
@lowjoel
lowjoel / gist:b0a2eb7bab69210580d0
Created Jul 25, 2014
mysql2 compile warnings on VC++
View gist:b0a2eb7bab69210580d0
have_header: checking for ruby/thread.h... -------------------- yes
"cl -nologo -Feconftest -IC:/Ruby210/include/ruby-2.1.0/x64-mswin64_120 -IC:/Ruby210/include/ruby-2.1.0/ruby/backward -IC:/Ruby210/include/ruby-2.1.0 -I. -IC:/Ruby210/include/ruby-2.1.0 -MD -Zi -W2 -wd4996 -we4028 -we4142 /O2 /GL -Zm600 conftest.c x64-msvcr120-ruby210.lib oldnames.lib user32.lib advapi32.lib shell32.lib ws2_32.lib iphlpapi.lib imagehlp.lib shlwapi.lib -link -incremental:no -debug -opt:ref -opt:icf -libpath:. -libpath:C:/Ruby210/lib "
conftest.c
Generating code
Finished generating code
checked program was:
/* begin */
1: #include "ruby.h"
2: