Skip to content

Instantly share code, notes, and snippets.

View endel's full-sized avatar

Endel Dreyer endel

View GitHub Profile
@endel
endel / dev_server.php
Last active March 5, 2016 15:29
Simple development server for running PHP projects without having to configure a web application server (nginx, apache, etc)
<?php
//
// Development server.
//
// Requires PHP 5.4+, with built-in web-server feature:
// http://php.net/manual/en/features.commandline.webserver.php
//
// Run it through console via:
// $ php -S localhost:8000 ./dev_server.php
//
@endel
endel / authors.yaml
Last active February 17, 2016 20:31
hook: Example configuration using `belongs_to` / `has_many` relationships and eager-loading. http://github.com/doubleleft/hook
# hook-ext/seeds/authors.yaml
# Generated through command `hook generate:seed authors`
#
# Seed for authors
#
truncate: true
data:
- _id: 1
name: Author one
@endel
endel / psd_export_layers_power_of_two.rb
Created December 22, 2015 14:05
Export Photoshop Layers into power-of-two sized images.
require 'json'
require 'psd'
def is_power_of_two(x)
n = x.to_i
while (((x % 2) == 0) && x > 1)
x = x/2
end
x == 1 && n != 1
end
@endel
endel / array-shufle.js
Created December 12, 2015 22:27
JavaScript one-liner Array shuffle
Array.prototype.shuffle = function() {
for(var j, x, i = this.length; i; j = Math.floor(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
return this;
}
@endel
endel / sample-large.json
Last active November 20, 2015 19:37
JSON samples used for benchmarking msgpack encoder/decoder.
[
{
"_id":"56490c18d9275a0003000000",
"author":null,
"created_at":"2015-11-15T22:50:00.170Z",
"description":"A weekly discussion by Ruby developers about programming, life, and careers.",
"image":"https://s3.amazonaws.com/devchat.tv/ruby-rogues-thumb.jpg",
"keywords":[
"Business",
"Careers",
@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() {