Skip to content

Instantly share code, notes, and snippets.

@nbhartiya
nbhartiya / complex_magic_input.js.jsx
Created August 4, 2015 02:01
Complex MagicInput
<MagicInput binding={[this, 'account.owner.email']} required_emoji={true} counter={true} />
@nbhartiya
nbhartiya / magic_input.js.jsx.coffee
Created August 4, 2015 01:55
Magic Input Component
MagicInput = React.createClass
getInitialState: ->
value = @getValue()
if value == ''
empty = true
else
empty = false
{empty: empty}
@nbhartiya
nbhartiya / react_bindings.js
Created August 4, 2015 01:23
How ReactJS bindings used to work
var NoLink = React.createClass({
getInitialState: function() {
return {message: 'Hello!'};
},
handleChange: function(event) {
this.setState({message: event.target.value});
},
render: function() {
var message = this.state.message;
return <input type="text" value={message} onChange={this.handleChange} />;
@nbhartiya
nbhartiya / magicinput.js.jsx.coffee
Created August 4, 2015 00:17
ReactJS Data Bindings with MagicInput
<MagicInput binding={[this, 'account.owner.email']} />
@nbhartiya
nbhartiya / javascript-widget-payload.js.coffee
Created March 25, 2015 22:07
Javascript Widget Payload Script
# Name your class anything you want. Here, I call it Foo.
# Note that by writing out our code in its own class, we namespace it.
class Foo
constructor: ->
# Here we just set the host to your website, but you might want to add a little variable here
# to make it www.staging.yourwebsite.com when you're in the staging environment and localhost:3000
# when you're in the development environment.
@host = "www.your-website.com"
# Makes the base of xml requests http when we are testing on localhost.
@nbhartiya
nbhartiya / javascript-widget-embedder.js
Created March 25, 2015 22:03
Javascript Widget Embedder Script
<script data-version='v1' data-client-id='clients-id' id='unique-embedder-id' type='text/javascript'>
// "data-version": It's useful to put the version of your embedder script in the "version" data
// attribute. This will enable you to more easily debug if any issues arise.
// "data-client-id": This id allows us to pull up the correct client's settings from our database.
// Each client may have different settings associated with their widget, and you can load them
// with this!
// "id": This HTML id allows us to refer to this embedder script's location. This is helpful
// if you want to inject html code in specific places in hour hosts's website or if you want to
// insert your payload script right next to this in the <head> tag.
@nbhartiya
nbhartiya / your_controller.rb
Created February 19, 2015 22:13
Javascript Embeddable Widget: Working with CORS
class YourController < ApplicationController
before_filter :cors_preflight_check, only: [:settings]
after_filter :cors_set_access_control_headers, only: [:settings]
def settings
# YOUR CODE TO GET CLIENT'S WIDGET SETTINGS HERE
end
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
@nbhartiya
nbhartiya / translator.py
Last active August 29, 2015 14:08
Ruby vs Python
import goslate
import random
class Trans:
def __init__(self, language):
self.gs = goslate.Goslate()
self.language = language
def translate(self,word):
print self.gs.translate(word, self.language)
var linkbuilt ="";
if(courseId !=undefined){
linkbuilt='http://new.culturealley.com/?courseId='+courseId+'&utm_source=facebook&utm_medium=FeedStatus&utm_campaign=FBFeedStatus';
}else{
linkbuilt='http://new.culturealley.com/?utm_source=facebook&utm_medium=FeedStatus&utm_campaign=FBFeedStatus'
}
FB.ui({
method: 'feed',
link: linkbuilt,
caption: "I started today and can already introduce myself in "+toLanguagePreference+".",
function postStory() {
var desc = 'Click to play games and learn '+ capitalizeFirstLetter(toLanguagePreference)+' with your fun and studious friend, '+ $('.userName').text() + ', now! '+$('.userName').text() +
' just learnt how to say ' +
((toLanguagePreference.toLowerCase() == 'mandarin') ?
lastLearntWords[0].word + ', ' + lastLearntWords[1].word + ', ' + lastLearntWords[2].word + ', and more in ':
lastLearntWords[0].meaning + ', ' + lastLearntWords[1].meaning + ', ' + lastLearntWords[2].meaning + ', and more in ') +
capitalizeFirstLetter(toLanguagePreference) +
'. Give this a "like" to encourage your friend!';
FB.api('app/objects/' + APP_NAMESPACE + ':word', 'POST', {
'access_token': APP_ID + '|' + APP_SECRET,