Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am pelish8 on github.
  • I am pelish8 (https://keybase.io/pelish8) on keybase.
  • I have a public key ASBaTN76JSotfD-yWMD39QweSpezsVHrbOgk5zbDasHTfQo

To claim this, I am signing this object:

@pelish8
pelish8 / copy-on-set.js
Created September 5, 2017 19:59
State is shared by multiple instances. On first set new deep copy of state will be created.
// copy-on-set
function Cos(state, parent) {
'use strict';
if (typeof this === 'undefined') {
return new Cos(state, parent);
}
state = state || {};
'use strict';
function propList(arr, ...props) {
if (typeof this === 'undefined') {
return new propList(arr, ...props);
}
this.arr = arr;
this._props = props;
return this;
}
@pelish8
pelish8 / UMD.js
Created July 14, 2015 14:46
UMD (Universal Module Definition) browser.
(function UMD(name, context, definition) {
if (typeof module !== 'undefined' && module.exports) {
module.exports = definition();
} else if (typeof define === 'function' && define.amd) {
define(definition);
} else {
context[name] = definition(name, context);
}
(function() {
var timeouts = [];
var messageName = 'set-immediate';
function setImmediate(fn) {
var params = [];
if (arguments.length > 1) {
params = Array.prototype.slice.call(arguments).slice(1);
}
timeouts.push({fn: fn, params: params});
@pelish8
pelish8 / gist:ed8ed7d23e34b5d2ba40
Created January 7, 2015 18:19
Finding image type from NSData or UIImage
+ (NSString *)contentTypeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
var el = ( function () {
var doc = document;
var directProperties = {
'class': 'className',
className: 'className',
defaultValue: 'defaultValue',
'for': 'htmlFor',
html: 'innerHTML',
- (void)viewDidAppear:(BOOL) animated {
[super viewDidAppear:animated];
// Register notification when the keyboard will be show
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
// Register notification when the keyboard will be hide
[[NSNotificationCenter defaultCenter] addObserver:self
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
/*!
* jQuery.scrollToElement
* Licensed under MIT
* https://gist.github.com/pelish8/9023893
* @author Aleksandar Stevic
* @version 0.0.1
*/
; (function ($) {
$.fn.scrollToElement = function (el, options) {
var $el = jQuery(el),