Skip to content

Instantly share code, notes, and snippets.

jwo / registrations_controller.rb
Created Sep 30, 2011
API JSON authentication with Devise
View registrations_controller.rb
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user =[:user])
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>, :status=>201
jwo / mysql.database.yml
Last active Apr 24, 2021
Sample config/database.yml from Rails. Postgres, MySQL, and SQLite
View mysql.database.yml
# Install the MYSQL driver
# gem install mysql2
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
# And be sure to use new-style password hashing:
jwo /
Last active Feb 22, 2021
Simple read-write lock in Rust. uses local variables; uses lazy_static to create a rw lock on a static variable.
use std::sync::RwLock;
extern crate lazy_static;
lazy_static! {
static ref MODELS: RwLock<i32> = RwLock::new(0);
fn update_it(number: i32) {
println!("You wanted me to update to {}", number);
jwo / map.js
Last active Dec 21, 2020
React google maps with multiple markers, only one info window
View map.js
import React, { Component } from "react"
import { compose } from "recompose"
import {
} from "react-google-maps"
jwo / query.graphql
Last active Nov 26, 2020
GraphQL Example for GitHub API repo statuses on a pull request. We know before hand that it's "jwo/react-hover-image" and pull request number 4
View query.graphql
repository(owner: "jwo", name:"react-hover-image"){
pullRequest(number: 4){
author {
jwo / query.graphql
Last active Nov 4, 2020
GraphQL example: current user's 100 most current public repos
View query.graphql
viewer {
repositories(privacy: PUBLIC, first: 3, orderBy: {field: PUSHED_AT, direction: DESC}) {
nodes {
jwo / index.js
Created Oct 26, 2017
Simple way to sign in with github for oAuth in Node/Express
View index.js
const express = require("express")
const app = express()
var passport = require("passport")
var session = require("express-session")
var GitHubStrategy = require("passport-github2").Strategy
const GITHUB_CLIENT_ID = "your-client-id-here" // or get from process.env.GITHUB_CLIENT_ID
const GITHUB_CLIENT_SECRET = "your-client-secret-here" // or get from process.env.GITHUB_CLIENT_SECRET
const GITHUB_CALLBACK_URL = "http://localhost:5000/auth/github/callback" // or get from process.env.GITHUB_CALLBACK_URL
jwo / index.html
Created Jun 14, 2017
Fetch data from star wars api and display
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<style media="screen">
.character {
display: flex;
width: 550px;
jwo / action.html.erb
Last active Apr 19, 2020
register React component on page with turbolinks working. The Rails parts (helper and ERB) are optional, but since this IS turbolinks, you probably ARE using rails.
View action.html.erb
<h1>Oh Hai</h1>
<%= react_component 'oh-hai' %>
jwo / App.js
Last active Apr 13, 2020
Notes before I blog about it: how-to-use-actioncable-and-npm-action-cable
View App.js
import React, { Component } from 'react';
import ActionCable from 'actioncable';
class App extends Component {
componentWillMount() {
var cable = ActionCable.createConsumer('ws://localhost:3000/cable')