Skip to content

Instantly share code, notes, and snippets.

View rendfall's full-sized avatar
💭
Coffee is a drink, not a language! ☕️

rendfall rendfall

💭
Coffee is a drink, not a language! ☕️
View GitHub Profile
git tag -l | xargs git tag -d
git fetch
@rendfall
rendfall / tilemap-array.js
Last active August 13, 2016 16:19
Simple implementation of tilemap rendering from array
// <canvas id="main"></canvas>
function init() {
// The two dimensional map array as it sounds is basically your world and what will be drawn.
// Each number can represet a different graphic or possible enviroment interaction.
// In this tutorial case we only have two possible tiles, zero which is blank and one which is filled.
var map = [
[1,0,1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,1],
[1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
@rendfall
rendfall / antispam.js
Created September 8, 2016 19:09
Anti-Spam Email Encoder
// Example for gmail accounts only >> rot13(tznvy.pbz)
function getEmail(u) {
var c = ':otliam'.split('').reverse().join('');
var a = String.fromCharCode('0'+8*8);
var h = 'tznvy.pbz'.replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
return c+u+a+h;
}
@rendfall
rendfall / proxy-observer.js
Created September 14, 2016 20:22
Use proxy like observer
let object = {};
object = new Proxy(object, {
set: (o, prop, value) => {
console.warn(`${prop} is set to ${value}`);
o[prop] = value;
},
get: (o, prop) => {
console.warn(`${prop} is read`);
return o[prop];
@rendfall
rendfall / get-remote-filesize.php
Created October 16, 2016 20:51
Get remote filesize
function getRemoteFilesize($url, $formatSize = true, $useHead = true) {
if (false !== $useHead) {
stream_context_set_default(array('http' => array('method' => 'HEAD')));
}
$head = array_change_key_case(get_headers($url, 1));
// content-length of download (in bytes), read from Content-Length: field
$clen = isset($head['content-length']) ? $head['content-length'] : 0;
// cannot retrieve file size, return "-1"
@rendfall
rendfall / get-average-color.js
Last active October 19, 2016 01:52
Get average color from image
(function (root) {
var canvas = document.createElement('canvas');
var context = canvas.getContext && canvas.getContext('2d');
var DEFAULT_RGB = { r: 0, g: 0, b: 0 };
function extractRGB(imageData) {
var len = imageData.data.length;
var rgb = { r: 0, g: 0, b: 0 };
var blockSize = 5; // Check every 5 pixels
var i = -4;
@rendfall
rendfall / invoke-once.js
Last active November 16, 2016 15:15
invokeOnce
function invokeOnce($element, eventType, handler, useCapture = false) {
var args = arguments;
$element.addEventListener(eventType, function selfRemoving(event) {
event.target.removeEventListener(event.type, selfRemoving, useCapture);
return handler.apply(handler, args);
});
}
@rendfall
rendfall / hosts.bat
Created January 19, 2017 23:02
CMD batch without UAC confirmation
runas /profile /user:Administrator /savecred "notepad C:\Windows\System32\drivers\etc\hosts"
@rendfall
rendfall / dom-helper.js
Created March 31, 2017 11:34 — forked from SitePointEditors/dom-helper.js
Mini jQuery, sort of.
/**
* A collection of helper prototype for everyday DOM traversal, manipulation,
* and event binding. Sort of a minimalist jQuery, mainly for demonstration
* purposes. MIT @ m3g4p0p
*/
window.$ = (function (undefined) {
/**
* Duration constants
* @type {Object}
@rendfall
rendfall / flexbox-grid.scss
Created May 21, 2017 23:10
Simple flexbox grid
@mixin element($e) {
&__#{$e} { @content; }
}
@mixin modifier($e) {
&--#{$e} { @content; }
}
.grid {
$gutter: 30px;