Skip to content

Instantly share code, notes, and snippets.

View remino's full-sized avatar

Rem remino

View GitHub Profile
@remino
remino / msconvert.js
Created January 5, 2012 05:37
JavaScript: Convert milliseconds to object with days, hours, minutes, and seconds
function convertMS(ms) {
var d, h, m, s;
s = Math.floor(ms / 1000);
m = Math.floor(s / 60);
s = s % 60;
h = Math.floor(m / 60);
m = m % 60;
d = Math.floor(h / 24);
h = h % 24;
return { d: d, h: h, m: m, s: s };
@remino
remino / ckrhetcrec.sh
Created January 2, 2021 03:28
ckrhetcrec
#!/bin/sh
# Enregistre l’émission Et cetera sur les ondes de Oui FM CKRH
# chaque vendredi soir à 20:00, heure d’Halifax.
#
# Executer regulièrement via cron :
# 59 7 * * 6 ckrhetcget.sh > /dev/null
set -e
@remino
remino / compression.rb
Created September 3, 2014 03:58
Ruby on Rails: Minify HTML, CSS, & JS, and compress with gzip https://remino.net/rails-html-css-js-gzip-compression/
# config/initializers/compression.rb
Rails.application.configure do
# Use environment names or environment variables:
# break unless Rails.env.production?
break unless ENV['ENABLE_COMPRESSION'] == '1'
# Strip all comments from JavaScript files, even copyright notices.
# By doing so, you are legally required to acknowledge
# the use of the software somewhere in your Web site or app:
@remino
remino / parse-jp-address.js
Created November 10, 2020 09:42
Parse Japanese address into an object
// Use at your own risk. Will not work for all Japanese addresses.
const regex = /^(.+[都道府県])?(.+?[市郡区町村]+)([^0-90-9ー- -]*)([0-90-9]+[丁目番地のー--]*(?:[0-90-9]+[番ー--]?(?:[0-90-9]+号?)?)?)?[\s ー-~-]*(.*)?/
const getMatch = (matches, index) => (matches ? matches[index] : null) || ''
const parseJpAddress = (str) => {
if (!str || !str.length) return {}
const matches = `${str}`.trim().match(regex)
@remino
remino / script.js
Last active March 24, 2020 07:45
New Node script using babel-node
#!/usr/bin/env npx babel-node --
// vim: ft=javascript
const readline = require('readline');
const minimist = require('minimist');
const { basename } = require('path');
const errors = {
general: 1,
missingArg: 16,
@remino
remino / Gemfile
Created January 9, 2014 18:01
kramdown-rails: Use Kramdown (Markdown) in Rails 4
# Gemfile
gem 'kramdown'
For
* ES5
* ES6
* CoffeeScript
@remino
remino / jsbookmarklet
Created April 19, 2018 01:31
jsbookmarklet – Minify JavaScript file as browser bookmarklet
#!/bin/sh
#
# jsbookmarklet
#
# remi@remino.net
# 2018-04-19
#
# Minify JavaScript file using uglify then save it to a file,
# output it to the screen, or copy the output to clipboard (macOS only),
# for usage as a browser bookmarklet.
@remino
remino / pre-commit
Created April 12, 2018 04:58 — forked from samhemelryk/pre-commit
A git pre-commit hook example.
#!/bin/bash
#
# This pre-commit hook checks that you havn't left and DONOTCOMMIT tokens in
# your code when you go to commit.
#
# To use this script copy it to .git/hooks/pre-commit and make it executable.
#
# This is provided just as an example of how to use a pre-commit hook to
# catch nasties in your code.
@remino
remino / jstnow.py
Created August 2, 2014 01:09
Python: Print date & time in JST time zone without pytz module
# Print date & time in JST time zone
# For Python 2.7.x without pytz module
import datetime
from datetime import datetime, timedelta, tzinfo
class JST(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=9)