Skip to content

Instantly share code, notes, and snippets.

@constantm
constantm / gist:0aa3d8398e72e4f5e7fe
Created August 21, 2015 14:18
Check whether paperclip attachment is exists in callback
In our app, we need to work out user profile completeness when a profile is saved. This is done via a callback. In this callback, we also check for the existance of Paperclip attachments.
This should supposedly be done with the following:
`@user.document.exists?`
That, however, returns false in the callback while a file is being uploaded. It looks like it's stuck in limbo between deleting the old file and saving the new one. A solution to this is to simply use the following:
`@user.document?`
@constantm
constantm / application.controller.js
Last active September 13, 2015 11:27
opportunity-select
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
@constantm
constantm / application.controller.js
Last active October 12, 2015 10:56
ember map cli test not working
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
coords: ["-26.2041028", "28.0473051"]
});
@constantm
constantm / tshirt.html
Last active July 15, 2016 08:56
tshirt popup
<div id="tshirt-claim">
<div class="close" onclick="document.getElementById('tshirt-claim').style.display = 'none';">&times;</div>
<img src="https://gifts.offerzen.com/tshirt.jpg" alt="Offerzen Tshirt">
<h3>Get a free shirt!</h3>
<h4>JSinSA attendees get a free tshirt, just complete Offerzen's onboarding.</h4>
<a class="button button-primary" href="https://www.offerzen.com?source=jsinsa&id=IDPARAMGOESHERE">Claim my tshirt</a>
</div>
<style>
#tshirt-claim {
def candidate_analytics_track(user)
# Alias user on Mixpanel so we can track unique visits -> signup
if cookies['visit_id']
Analytics.alias(previous_id: cookies[:visit_id], user_id: user._id.to_s)
Analytics.flush # We need this to prevent race conditions and split profiles on Mixpanel
cookies.delete :visit_id
end
Analytics.identify(
user_id: "#{user._id}",
@constantm
constantm / Ruby countries hash
Last active October 27, 2016 01:52 — forked from vxnick/gist:380904
Ruby countries hash
countries = {
'AF' => 'Afghanistan',
'AX' => 'Aland Islands',
'AL' => 'Albania',
'DZ' => 'Algeria',
'AS' => 'American Samoa',
'AD' => 'Andorra',
'AO' => 'Angola',
'AI' => 'Anguilla',
'AQ' => 'Antarctica',
@constantm
constantm / cheatsheet.md
Last active February 21, 2017 10:19
Shopify theme commands cheat sheet

##Configure existing theme on store:

theme configure --themeid=12345 --password=12345 --store=yourshop.myshopify.com

##Setup up new theme

theme configure --themeid=12345 --password=12345 --store=yourshop.myshopify.com
@constantm
constantm / test-output.sh
Created March 6, 2018 14:32
VueJS borked tests
➜ git:(vueJS-user-list) ✗ yarn test
yarn run v1.3.2
$ jest --config spec/vue/jest.conf.json
FAIL spec/vue/users-add-remove.spec.js
UsersAddRemove
✕ loads users from remote JSON endpoint and renders table (1531ms)
● UsersAddRemove › loads users from remote JSON endpoint and renders table
expect(string).toContain(value)
@constantm
constantm / gist:764192168f02733fe264
Last active December 5, 2018 10:13
Straight forward deployment of Ember on Semaphore CI
npm install ember-cli -g
npm install
bower install
ember build
ssh-keyscan host.com >> ~/.ssh/known_hosts
tar -cvf tmp.tar.gz -C dist .
scp -r tmp.tar.gz user@host.com:/var/www/versions/
ssh user@host.com "mkdir -p /var/www/versions/$REVISION && tar -xf /var/www/versions/tmp.tar.gz -C /var/www/versions/$REVISION/ && rm /var/www/versions/tmp.tar.gz && rm /var/www/current && ln -s /var/www/versions/$REVISION/ /var/www/current && ls -tr /var/www/leaply-ember/versions | head -n -3 | xargs rm -rf"