Skip to content

Instantly share code, notes, and snippets.

@sankalpk
sankalpk / .babelrc
Last active November 5, 2016 02:28
Hot reload with webpack-rails, react, and relay
/* ./babelrc */
{
"plugins": ["./babelRelayPlugin"],
"presets": ["react", "es2015", "stage-0"],
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
@sankalpk
sankalpk / oauth_request.js
Created September 8, 2016 17:20
OAuth make simple request
var request = require('request');
var accessToken = 'ACCESS_TOKEN_HERE';
request({
url: 'https://api.someapi.com/blah/something',
auth: {
'bearer': accessToken
}
}, function(err, res) {
@sankalpk
sankalpk / post_once_exactly.rb
Last active October 15, 2015 22:46
Post once exactly in Rails
# Put in controller action
def create
post_once_exactly(params[:uuid]) do
# do some stuff
end
end
# Put in API base controller
def post_once_exactly uuid
if(uuid.nil? || !$redis.sadd("post_requests", uuid))
@sankalpk
sankalpk / image_proxy_controller.rb
Last active December 29, 2017 11:23
Image proxy in Rails
class ImageProxyController
def show
image = open(params[:url]) {|f| f.read }
send_data image, type: "image/jpeg", disposition: 'inline'
end
end
@sankalpk
sankalpk / replace_whitespace_snippet
Created March 9, 2015 17:28
Remove white spaces from Liquid template
{{ customer.first_name | replace: ' ','' }}
@sankalpk
sankalpk / openshiftconsole.md
Last active August 29, 2015 14:00
How to open rails console in OpenShift from the terminal/command line

First SSH into your application

rhc ssh <app name>

Once into OpenShift, go to your repo directory and open Rails console

cd app-root/repo
bundle exec rails console production

Note that this last command takes a while for OpenShift to load. But you should be in after some time.