Skip to content

Instantly share code, notes, and snippets.

View endel's full-sized avatar

Endel Dreyer endel

View GitHub Profile
@endel
endel / number-pad-zero.js
Last active August 1, 2023 11:54
Simplest way for leading zero padding in JavaScript
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
(1).pad(3) // => "001"
(10).pad(3) // => "010"
(100).pad(3) // => "100"
@endel
endel / opengraph.rb
Last active November 7, 2015 16:18
Simplest way to extract OpenGraph tags from HTML in Ruby
html = Faraday.get("http://ogp.me").body
if (data = html.scan(/property=["|']og:(.*)["|'].*content=["|'](.*)["|']/))
og = OpenStruct.new(Hash[ data ])
puts og.inspect
end
@endel
endel / How-to-use.md
Last active October 28, 2015 10:10
FontForge: Straightforward way to convert .ttf into multiple webfont formats
chmod +x convert.pe
./conver.pe Your-Font.ttf
@endel
endel / running-gulp-from-another-directory.sh
Created September 28, 2015 00:02
Running gulp from another directory
node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../gulpfile.js --cwd ../../ build
@endel
endel / threejs-json-atlas-loader.js
Last active September 13, 2021 13:11 — forked from momo-the-monster/threejsatlasloader.js
three.js - JSON Atlas Loader
// three.js JSON Atlas Loader
// Requires: whatwg-fetch (https://github.com/github/fetch)
var materials = {}
fetch('images/spritesheet.json').then(function(response) {
return response.json()
}).then(function(json) {
var atlasTexture = THREE.ImageUtils.loadTexture('images/' + json.meta.image, undefined, function() {
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.PIXI = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (process){
/*!
* async
* https://github.com/caolan/async
*
* Copyright 2010-2014 Caolan McMahon
* Released under the MIT license
*/
/*jshint onevar: false, indent:
@endel
endel / gist:39a53f5fa4370f76d872
Last active August 29, 2015 14:22
hook installation output
[ 1:45:24] endel:~/Projects
$ curl -sSL https://raw.githubusercontent.com/doubleleft/hook/master/scripts/install.sh | bash
Cloning into 'hook'...
remote: Counting objects: 248, done.
remote: Compressing objects: 100% (219/219), done.
remote: Total 248 (delta 9), reused 120 (delta 6), pack-reused 0
Receiving objects: 100% (248/248), 155.39 KiB | 0 bytes/s, done.
Resolving deltas: 100% (9/9), done.
Checking connectivity... done.
# check dependencies
@endel
endel / convert.rb
Last active August 29, 2015 14:19
RPG Maker Sprite-Sheet extractor. It generates a separate .png file for each sprite.
# RPG Maker sprite-sheet extractor
require 'fileutils'
target_file = File.basename(ARGV[0], File.extname(ARGV[0]))
output_dir = "#{File.dirname(ARGV[0])}/#{target_file}"
FileUtils.mkdir_p(output_dir)
# extract each sprite
%x(convert #{ARGV[0]} -crop 24x32 #{output_dir}/sprite-%03d.png)
@endel
endel / getMoonPhase.js
Created March 25, 2015 16:04
Get Moon Phase by Date, written in JavaScript
/*
* modified from http://www.voidware.com/moon_phase.htm
*/
function getMoonPhase(year, month, day)
{
var c = e = jd = b = 0;
if (month < 3) {
year--;
@endel
endel / authentication.js
Last active March 24, 2016 08:55
ng-admin authentication with hook https://github.com/doubleleft/hook
var app = angular.module('admin', ['ng-admin']),
hook = new Hook.Client({...});
var headerNav, pageWrapper, restangular;
if (hook.auth.currentUser && hook.auth.currentUser.role != 'admin') {
hook.auth.logout();
}
function hideMenu() {