Skip to content

Instantly share code, notes, and snippets.

@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.

@sankalpk
sankalpk / replace_whitespace_snippet
Created March 9, 2015 17:28
Remove white spaces from Liquid template
{{ customer.first_name | replace: ' ','' }}
@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 / 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 / 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 / .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 / webpack-dev-server.js
Last active November 5, 2016 02:21
Webpack-rails with hot module reloading (HMR)
/* ./webpack-dev-server */
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const chalk = require('chalk');
const webpackConfig = require('./config/webpack.config.js');
const webpackDev = new WebpackDevServer(webpack(webpackConfig), {
contentBase: '/webpack/',
stats: {
Verifying my Blockstack ID is secured with the address 1NMMG2avQ52vbDc1chhXTBPVCB1tA7hJiZ https://explorer.blockstack.org/address/1NMMG2avQ52vbDc1chhXTBPVCB1tA7hJiZ
@sankalpk
sankalpk / renew_square_access_token.rb
Created July 1, 2018 19:30
Update or Renew Square Access Token Using Ruby
require 'net/http'
def new_access_token(square_application_id, square_secret, square_access_token)
url = "https://connect.squareup.com/oauth2/clients/#{square_application_id}/access-token/renew"
headers = {
'Content-Type': 'application/json',
'Authorization': "Client #{square_secret}"
}
@sankalpk
sankalpk / convert.rb
Created July 4, 2018 16:15
Convert form to form template in Cloverbook
email = "<INSERT_EMAIL_HERE>"
form_graph_id = "<INSERT_GRAPH_ID_HERE"
user = User.find_by_email
form = Form.find(GraphQL::Schema::UniqueWithinType.decode(form_graph_id)[1])
FormTemplate.create!(
user_id: user.id,
brand_id: user.primary_brand.id,
schema: form.schema,