Skip to content

Instantly share code, notes, and snippets.

View mrgenixus's full-sized avatar

Ben West mrgenixus

View GitHub Profile
class Component extends React.Component {
onScroll(event) {
this.scrollPosition = getScrollPosition(event);
if (this.scrolling) return;
this.scrolling = true;
const processLongOperation = (beginPosition) => {
longOperation(beginPosition, (completionState) => {
this.setState(completionState, () => {
//rendered
@mrgenixus
mrgenixus / args.rb
Last active August 30, 2019 02:11
arguments in ruby
def func a, c, d
puts "a: " + a.to_s
puts "c: " + c.to_s
puts "d: " + d.to_s
end
def func2 *args
puts args.to_s
end
@mrgenixus
mrgenixus / classes.js
Created March 7, 2018 23:09
es6 classes
function ParentWidget(properties) {
Object.assign(this, properties);
}
function farewell() {
console.log('Goodbye Cruel ' + this.name);
}
ParentWidget.prototype.farewell = farewell;
export function stub(obj, method, callback=_.noop, { as:name, returns }) {
beforeEach(function() {
const stub = this.sinon.stub(obj, 'method', (...args) => {
callback.call(this, ...args);
});
if (returns) stub.returns(returns);
if (name) _.set(this, name, stub);
});
@mrgenixus
mrgenixus / index_service_options.rb
Last active May 24, 2017 21:14
Chainable Options
class IndexService
class IndexServiceOptions
def date_range start_date, end_date
new @host, @values.merge(date_range: [start_date, end_date])
end
def hide_removed hide_removed=true
new @host, @values.merge hide_removed: hide_removed
end
@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 / redux.js
Created December 2, 2016 22:53
plan to eat redux
// redux starts with the store.- ish
const store = Redux.createStore(function(state, action) {
return rootReducer(state, action);
});
// next, components and other kinds of (what I'll call) mappers dispatch actions to the store
store.dispatch({
type: 'THIS_IS_A_TYPE_OF_ACTION'
});
375 x Fusion Thruster
863 x Radar Sensor Cluster
6,000 x Nanoelectrical Microprocessor
37,500 x Tungsten Carbide Armor Plate
225 x Antimatter Reactor Unit
3,000 x Tesseract Capacitor Unit
3,795 x Linear Shield Emitter
975 x Morphite
450 x Construction Blocks
1 x Apocalypse
@mrgenixus
mrgenixus / time_stamp_reducer.js
Created August 22, 2016 21:51
TimeStampReducer
export default function recordTime(target, state, action) {
if (action.type === target) return new Date().toDateTimeString();
if (action.type === target) return moment().format('iso9660'); // is this a thing?
return state;
}