Skip to content

Instantly share code, notes, and snippets.

@scan
scan / Dockerfile
Created May 4, 2017 08:58
Dockerfile for alpine based rails app
FROM ruby:2.4.1-alpine
RUN apk --update --upgrade add build-base nodejs libxml2-dev libxslt-dev tzdata
RUN mkdir /app
WORKDIR /app
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN bundle config --global build.nokogiri "--use-system-libraries" && bundle install --jobs 4
module Rescuable
extend ActiveSupport::Concern
module ClassMethods
def rescue_methods(*methods, from: nil, &block)
raise ArgumentError, 'Requires exception to rescue from' if from.blank?
from = [from] if !from.respond_to?(:any?)
methods.each do |method|
old_method = "_#{method}".to_sym
@scan
scan / weeks.rb
Last active April 20, 2016 15:08
Get the calendar week number from a date
module Weeks
def current_week
Date.today.strftime('%U').to_i
end
def weeks_this_year
Date.today_end_of_year.strftime('%U').to_i
end
end
@scan
scan / Connector.java
Created January 29, 2015 12:40
A simple class to check connections with JDBC
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class Connector {
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
private static final String HOST = "localhost";
private static final short PORT = 3306;
public class AccountAuthenticator extends AbstractAccountAuthenticator {
private final Context context;
@Inject @ClientId String clientId;
@Inject @ClientSecret String clientSecret;
@Inject ApiService apiService;
public AccountAuthenticator(Context context) {
super(context);
/*
* Copyright 2014 Chris Banes
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
menu = new MenuWrapper(menu) {
private MenuItem fix(MenuItem item) {
try {
Field f = item.getClass().getDeclaredField("mEmulateProviderVisibilityOverride");
f.setAccessible(true);
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
@scan
scan / srt2vtt.pl
Created October 1, 2014 12:58
SubRip .srt to WebVTT .vtt converter
#!/usr/bin/env perl -w
print "WEBVTT\n\n";
while(<>) {
s/(\d),(\d)/$1.$2/g if /--\>/;
s/^[ \t]+//;
s/[ \t]+$//;
s/\r\n$/\n/;
@scan
scan / mp3.js
Created August 21, 2014 06:44 — forked from dtrce/mp3.js
var http = require('http'),
fileSystem = require('fs'),
path = require('path')
util = require('util');
http.createServer(function(request, response) {
var filePath = 'path_to_file.mp3';
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {