Skip to content

Instantly share code, notes, and snippets.

Working from home

mech mech

Working from home
  • Career Pacific / Jobline
  • Singapore, Tampines
View GitHub Profile
mech / association_loader.rb
Created Sep 22, 2017 — forked from theorygeek/association_loader.rb
Preloading Associations with graphql-batch
View association_loader.rb
# frozen_string_literal: true
class AssociationLoader < GraphQL::Batch::Loader
attr_reader :klass, :association
def initialize(klass, association)
raise ArgumentError, "association to load must be a symbol (got #{association.inspect})" unless association.is_a?(Symbol)
raise ArgumentError, "cannot load associations for class #{}" unless klass < ActiveRecord::Base
raise TypeError, "association #{association} does not exist on #{}" unless klass.reflect_on_association(association)
@klass = klass
mech / jquery.ajax.progress.js
Created Jul 5, 2016 — forked from db/jquery.ajax.progress.js
add XHR2 progress events to jQuery.ajax
View jquery.ajax.progress.js
(function addXhrProgressEvent($) {
var originalXhr = $.ajaxSettings.xhr;
progress: function() { console.log("standard progress callback"); },
xhr: function() {
var req = originalXhr(), that = this;
if (req) {
if (typeof req.addEventListener == "function") {
req.addEventListener("progress", function(evt) {
mech / AddContact.jsx
Created Apr 22, 2016 — forked from dvonlehman/AddContact.jsx
React without flux or redux complexity
View AddContact.jsx
import React from 'react';
import request from 'superagent';
// This import syntax requires the babel transform-export-extensions plugin
import dispatcher, {actions} from '../lib/dispatcher';
export default class AddContact extends React.Component {
submitHandler(event) {'/api/contacts')
firstName: this.refs.firstName.value,
View exercise.js
import React from 'react'
import assign from 'object-assign'
var styles = {}
class Autocomplete extends React.Component {
static propTypes = {
initialValue: React.PropTypes.any,
onChange: React.PropTypes.func,
View gist:f4002d7031b8541e857a
"query": {
"function_score": {
"query": {
"bool": {
"must": {
"multi_match": {"query": "Renaissance", "fields": ["name", "company"]},
"term": {"features": "disability_access"},
"should": {
View 0.
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
# Deployment structure
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select

In Rails 3

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/

(e.g. app/models/concerns/, app/models/products/)

mech / education.rb
Last active Dec 15, 2015
Trying to see how DDD can help in modeling ATS's Education model.
View education.rb
# Entity - Represent an important domain concept with identity and life cycle.
class Education
def initialize(institution, course, when)
@institution = # Institution is an Value Object that is immutable
@course = Course.for(course) # Course is an Value Object too
@period = period(when) # PostgreSQL's daterange Range Type
def course_ended? # Query method - Based on period, is CA still studying?