Skip to content

Instantly share code, notes, and snippets.

View mrgenixus's full-sized avatar

Benjamin West mrgenixus

View GitHub Profile
@mrgenixus
mrgenixus / isDblTouchTap.js
Created May 22, 2017 16:44 — forked from MoOx/isDblTouchTap.js
Double touch tap workaround for React based on onTouchTap (react-tap-event-plugin)
const dblTouchTapMaxDelay = 300
let latestTouchTap = {
time: 0,
target: null,
}
export default function isDblTouchTap(event) {
const touchTap = {
time: new Date().getTime(),
target: event.currentTarget,
@mrgenixus
mrgenixus / no-select.scss
Created February 1, 2017 18:16 — forked from nathos/no-select.scss
Sass (SCSS) mixin to disable user-select on an element
@mixin no-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-touch-callout: none;
-ms-text-size-adjust: none;
@mrgenixus
mrgenixus / active_model_lint.rb
Created February 26, 2016 14:26 — forked from dmitriy-kiriyenko/active_model_lint.rb
ActiveModel lint tests for rspec
# put the file into spec/support
shared_examples_for "ActiveModel" do
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
example m.gsub('_',' ') do
send m
end
end
@mrgenixus
mrgenixus / console.log short
Last active October 15, 2015 01:01 — forked from DaveVoyles/console.log short
Got tired of writing console.log everywhere
var c = console.log.bind(console); // allows you to replace console.log(message) in your code with c(message)
module Starbucks
def self.order(&block)
order = Order.new
order.instance_eval(&block)
return order.drinks
end
class Order
(function (n) { // function has no name, is therefore "anonymous"
var i=n*2;
if (i > 4) {
return undefinedFunc(); // causes a "ReferenceError: undefinedFunc is not defined at Object.<anonymous>"
} else {
arguments.callee(i); // recurses, adding the anonymous function to the call stack
}
})(1);
/*
* This decorates Handlebars.js with the ability to load
* templates from an external source, with light caching.
*
* To render a template, pass a closure that will receive the
* template as a function parameter, eg,
* T.render('templateName', function(t) {
* $('#somediv').html( t() );
* });
* Source: https://github.com/wycats/handlebars.js/issues/82
$(function(){
$('*[data-repeat]').each(function(){
var n = $(this).data('repeat');
var parent = $(this).parent();
self = $(this);
for (var i = 0; i < n; i++) {
parent.append(self.clone());
}
})
});
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
var double = function(a){ return a * 2; }
var getterSetter = (function(){ //don't work in the global scope
var process_validation = function(validation_params){
if (validation_params) return function(val){
// do magjiks
if (validation_params.filter) val = val.match(validation_params.filter)[0];
if (validation.process && typeof validation.process == 'function') val = validation.process(val);
if (validation_params.min) val = Math.max(val,validation_params.min);