Skip to content

Instantly share code, notes, and snippets.

View jbueza's full-sized avatar

Jaime Bueza jbueza

View GitHub Profile
@jbueza
jbueza / export-ibooks.js
Last active March 20, 2021 01:13
Export your iBooks (epub) on Mac OS X. Useful if you're moving your book collection away from Books.app (Mac OS X) to Calibre (open source and works on all major operating systems).
const fs = require('fs');
const plist = require('simple-plist');
const slug = require('slug');
const homedir = require('os').homedir();
const {execSync} = require('child_process');
const SCRIPT_NAME = 'ibooks export';
console.time(SCRIPT_NAME);
@jbueza
jbueza / download-webm.js
Created March 20, 2021 01:10
Using nodejs and axios to download webm file
const fs = require('fs');
const axios = require('axios');
(async () => {
try {
const {data} = await axios.get(SOME_URL_TO_WEBM_FILE, {responseType: 'arraybuffer'});
return fs.writeFileSync(`test.webm`, data, 'binary');
} catch (err) {
console.log(err);
}
@jbueza
jbueza / lol.css
Last active September 7, 2018 23:44
.trololol {
position: fixed !important;
top: 0 !important;
right: 0 !important;
background-color: red !important;;
}
@jbueza
jbueza / http-to-https.js
Last active April 15, 2016 16:19
NodeJS, Express, Elastic Beanstalk, Elastic Load Balancer (Redirect HTTP to HTTPS)
app.use(function(req, res, next) {
if ((!req.secure) && (req.get('X-Forwarded-Proto') !== 'https')) {
res.redirect('https://' + req.get('Host') + req.url);
} else {
next();
}
});
@jbueza
jbueza / gist:11002634
Created April 17, 2014 18:18
Calculate number of rounds in a losers bracket (double elimination)
Math.ceil( (Math.log(teams)/Math.log(2)) / Math.log(2)) / Math.log(2)) + Math.ceil(Math.log(teams)/Math.log(2))
var teams = 128;
var initialRounds = Math.ceil(Math.log(teams)/Math.log(2));
var surplus = Math.ceil( Math.log(initialRounds)/Math.log(2) );
console.log(initialRounds);
console.log(surplus);
@jbueza
jbueza / prepare-commit-msg
Last active August 29, 2015 13:57
Adding more cats and wolves to the commit messages
#!/bin/sh
#
# Automatically add branch name and branch description to every commit message except merge commit.
#
COMMIT_EDITMSG=$1
addBranchName() {
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
fe60357 (HEAD, FEATURE-MAKE_CAT_FLUFFYLOL) [FEATURE-MAKE_CAT_FLUFFYLOL]: Integrating fluffy cats
@jbueza
jbueza / prepare-commit-msg
Created March 4, 2014 18:30
Automatically add branch name and branch description to every commit message except merge commit.
#!/bin/sh
#
# Automatically add branch name and branch description to every commit message except merge commit.
#
COMMIT_EDITMSG=$1
addBranchName() {
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)

(from http://www.joyceleong.com/log/installing-phantomjs-on-ubuntu/)

  1. cd ~
  2. wget http://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2
  3. sudo mv ~/phantomjs-1.9.1-linux-x86_64.tar.bz2 /usr/local/share
  4. cd /usr/local/share
  5. sudo tar xvf phantomjs-1.9.1-linux-x86_64.tar.bz2
  6. sudo ln -s /usr/local/share/phantomjs-1.9.1-linux-x86_64 /usr/local/share/phantomjs
  7. sudo ln -s /usr/local/share/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
  8. phantomjs --version
@jbueza
jbueza / SomeCode.js
Created October 26, 2012 09:09
Provides an easy way of retrieving a specific entity by Partition and RowKey.
var Dre = require("dre");
var dre = new Dre(account); // account is just a JSON object with your Azure Storage keys
var Person = dre.model("People", dre.Schema({
FirstName: "string",
LastName: "string"
}));
Person.findOne({