Skip to content

Instantly share code, notes, and snippets.

View santosh-btc's full-sized avatar

Santosh Sharma santosh-btc

  • Japan
View GitHub Profile
@santosh-btc
santosh-btc / pinterest_spammer.rb
Created March 10, 2017 18:01 — forked from ericchen/pinterest_spammer.rb
Post to Pinterest using Ruby and Mechanize
# Usage example:
#
# s = PinterestSpammer.new
# s.sign_in 'your_account_email', 'your_account_password'
# s.get_boards # get boards list, that contains board_id (for example - 455708124733779520)
# s.create_pin(455708124733779520, 'https://xyz.xyz/', 'http://rubyonrails.org/images/rails.png', 'Spammer!')
#
#
require 'mechanize'
class PinterestSpammer
@santosh-btc
santosh-btc / RubyUtils.js
Created August 19, 2017 10:50 — forked from AnkurVyas-BTC/RubyUtils.js
Ruby's String Utils: center, rjust, ljust in JS
/*
* Ruby's String#center, String#rjust, String#ljust
*
* https://jsfiddle.net/6v0bpffm/
*/
function ljust( string, width, padding ) {
padding = padding || " ";
padding = padding.substr( 0, 1 );
if ( string.length < width )
import { createStore, combineReducers } from 'redux';
import { reducer as reduxFormReducer } from 'redux-form';
const reducer = combineReducers({
form: reduxFormReducer,
});
const store = (window.devToolsExtension
? window.devToolsExtension()(createStore)
: createStore)(reducer);
import React from 'react';
import { Field, reduxForm } from 'redux-form';
const SimpleForm = props => {
const { handleSubmit, pristine, reset, submitting } = props;
return (
<form onSubmit={handleSubmit}>
<div>
<label>First Name</label>
<div>
import React, { Component } from 'react';
import { Provider } from "react-redux";
import store from "./store";
import showResults from "./showResults";
import SimpleForm from "./SimpleForm";
class App extends Component {
render() {
return (
<Provider store={store}>
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
export default (async function showResults(values) {
await sleep(500);
window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`);
});
<div>
<label>First Name</label>
<div>
<Field
name="firstName"
component="input"
type="text"
placeholder="First Name"
/>
</div>
function validate(values) {
const errors = {}
if (!values.firstName) {
errors.firstName = 'Required'
}
return errors
}
const renderField = ({
input,
type,
meta: { touched, error }
}) => (
<div>
<label>{label}</label>
<div>
<input {...input} placeholder={label} type={type} />
{touched && error && <span>{error}</span>}
<div>
<label>First Name</label>
<div>
<Field
name="firstName"
component={renderField}
type="text"
placeholder="First Name"
/>
</div>