Skip to content

Instantly share code, notes, and snippets.

@emilong
emilong / html2haml.rb
Created April 1, 2012 19:48
Convert HTML to HAML
require 'rubygems'
require 'find'
require 'haml'
require 'haml/html'
Find.find("content") do |path|
if path.end_with? "htm"
File.open(path) do |input|
File.open(path + "l.haml", "w") do |output|
output.write Haml::HTML.new(input.read).render
@emilong
emilong / Bean.java
Created February 15, 2014 19:03
A suggested builder-style bean pattern
/* Traditional bean */
public class Bean {
private String foo;
private String bar;
private int baz;
public Bean() {
}
public Bean(String foo, String bar, int baz) {
@emilong
emilong / mariadb.md
Last active August 29, 2015 14:06
MariaDB ActiveRecord JDBC Rails configuration

In your Gemfile:

gem 'activerecord-jdbc-adapter'
gem 'jdbc-mariadb'

In your database.yml

development:

adapter: mariadb

@emilong
emilong / GsonTest.java
Created February 17, 2015 22:14
How Gson serializes a byte array
import com.google.gson.Gson;
import java.security.MessageDigest;
public class GsonTest {
private final byte[] sha1;
public GsonTest(byte[] sha1) {
this.sha1 = sha1;
}
@emilong
emilong / gist:ae451ab6c0332b5392e9
Created March 18, 2015 21:53
Proguard in a gradle for a pure Java project
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:5.2'
}
}
$ java -jar ./build/libs/jruby-dropwizard-service-1.0+7c593cf.jar
usage: java -jar jruby-dropwizard-service-1.0+7c593cf.jar
[-h] [-v] {server,check} ...
positional arguments:
{server,check} available commands
optional arguments:
-h, --help show this help message and exit
-v, --version show the application version and exit
@emilong
emilong / gist:d4348b17988c186a8347
Last active November 23, 2017 08:45
Run chrome on OSX, disabling DHE
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --cipher-suite-blacklist=0x0011,0x0012,0x0013,0x0014,0x0015,0x0016,0x002D,0x0032,0x0033,0x0038,0x0039,0x0040,0x0044,0x0045,0x0063,0x0065,0x0066,0x0067,0x006A,0x006B,0x0087,0x0088,0x008E,0x008F,0x0090,0x0091,0x0099,0x009A,0x009E,0x009F,0x00A2,0x00A3,0x00AA,0x00AB,0x00B2,0x00B3,0x00B4,0x00B5
function DeadMansSwitchGmailCheckIn() {
var messages = Gmail.Users.Messages.list("me", { q: "from: no-reply@example.com label:unread" });
if (messages.messages && messages.messages.length > 0) {
Logger.log(UrlFetchApp.fetch("Your Snitch URL"));
for (var i = 0; i < messages.messages.length; i++) {
var message = messages.messages[i];
Gmail.Users.Messages.modify({"removeLabelIds": ["UNREAD"]}, "me", message.id);
}
const Content = require(“../models/content”);
const PdfApi = require('some-pdf-service-api-client');
PdfApi.configure(process.env.PDF_API_KEY);
modules.export = {
generate: function(contentId) {
const content = Content.find(contentId);
return PdfApi.render(content.format());
}
// Factory
function createPdfGenerator(Content, PdfApi) {
return {
generate: function(contentId) {
const content = Content.find(contentId);
return PdfApi.render(content.format());
}
};
}