Skip to content

Instantly share code, notes, and snippets.

View ptgamr's full-sized avatar

Anh Trinh ptgamr

View GitHub Profile
import Ember from 'ember';
export { dirtyHasMany, dirtyBelongsTo, dirtyMixin };
var dirty = 'relationshipIsDirty';
function dirtyMixin (obj) {
var args = Object.keys(obj);
var comp = Ember.computed;
args.push('isDirty');
obj[dirty] = comp.any.apply(comp, args);
@ptgamr
ptgamr / team.js
Created October 1, 2015 08:49 — forked from poteto/team.js
import Ember from 'ember';
import DS from 'ember-data';
var computed = Ember.computed;
var get = Ember.get;
var RSVP = Ember.RSVP;
export default DS.Model.extend({
name: DS.attr('string'),
players: DS.hasMany('player', { async: true }),
@ptgamr
ptgamr / Object Flatten
Created October 31, 2015 11:25 — forked from penguinboy/Object Flatten
Flatten javascript objects into a single-depth object
var flattenObject = function(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
for (var x in flatObject) {
if (!flatObject.hasOwnProperty(x)) continue;
@ptgamr
ptgamr / setup_dokku.sh
Created November 2, 2015 09:17 — forked from plasticut/setup_dokku.sh
Setup dokku
export DOKKU_HOST=$HOSTNAME
export PUBLIC_KEY=~/.ssh/id_rsa.pub
export DEVELOPER=john
cat $PUBLIC_KEY | ssh root@$DOKKU_HOST "sudo sshcommand acl-add dokku $DEVELOPER"
@ptgamr
ptgamr / ember_examples.md
Created November 16, 2015 10:50 — forked from rwjblue/ember_examples.md
Ember Examples
@ptgamr
ptgamr / ngram-search.sh
Created May 5, 2016 13:33 — forked from avar/ngram-search.sh
ElasticSearch fuzzy ngram powered search
export http_proxy=
export https_proxy=
curl -XDELETE 'http://localhost:9200/test/'
echo "Creating the mapping"
curl -XPUT 'http://localhost:9200/test/?pretty=1' -d '
{
"mappings" : {
"member" : {
@ptgamr
ptgamr / Sharded mongodb environment on localhost
Created May 6, 2016 12:26 — forked from joewagner/Sharded mongodb environment on localhost
Bash shell script that sets up a sharded mongodb cluster on a single machine. Handy for testing or development when a sharded deployment is required. Notice that this will remove everything in the data/config and data/shard directories. If you are using those for something else, you may want to edit this...
# clean everything up
echo "killing mongod and mongos"
killall mongod
killall mongos
echo "removing data files"
rm -rf data/config
rm -rf data/shard*
# For mac make sure rlimits are high enough to open all necessary connections
ulimit -n 2048
@ptgamr
ptgamr / README.md
Created April 21, 2017 13:02 — forked from mik01aj/README.md
How to use Tether with React

Tether is a great library for positioning stuff (tooltips, modals, hints, etc) in your web app.

But, as I use React, it was pretty problematic for me, as Tether mutates the DOM and React breaks miserably when it sees mutated DOM. The solution is to have the tethered element outside the part of the DOM tree which is controlled by React (in this case, I use document.body).

That's why I created 2 helpers to use Tether with React.

The first one, TetheredElement is a plain JS helper to create a new element, attach it to some other one via Tether, and populate it with some React component.

The second one, TetherTarget is a React component and it uses TetheredElement to integrate it further with React, so that you can attach components to each other with Tether, without leaving the cozy React/JSX world and worrying about manual DOM operations. Just write:

@ptgamr
ptgamr / Ubuntu-Compass-ruby[16.04]
Created March 24, 2018 10:36 — forked from AungMyoKyaw/Ubuntu-Compass-ruby[16.04]
Compass installation for ubuntu 16.04
[https://gist.github.com/stephou0104/233b5c99884f1d8c8b8b#file-ubuntu-compass-ruby]
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
@ptgamr
ptgamr / alacritty.yml
Created August 13, 2018 10:12
~/.config/alacritty/alacritty.yml
# Configuration for Alacritty, the GPU enhanced terminal emulator
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty it self.
env:
# TERM env customization. Default is xterm-256color
# Note: the default TERM value `xterm-256color` does not
# specify all features alacritty supports. This does pose