Skip to content

Instantly share code, notes, and snippets.

View johnnyji's full-sized avatar
🏠
Working from home

Johnny Ji johnnyji

🏠
Working from home
View GitHub Profile
@johnnyji
johnnyji / candidates.rb
Last active August 29, 2015 14:18
candidates exercise
require 'active_support/all'
@candidates = [
{
id: 5,
years_of_experience: 4,
github_points: 293,
languages: ['C', 'Ruby', 'Python', 'Clojure'],
date_applied: 5.days.ago.to_date,
age: 26
@johnnyji
johnnyji / gist:d1226c9467a51f7d8b39
Created June 16, 2015 21:46
Rubocop pre-commit hook
#!/bin/sh
#
# Check for ruby style errors
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
NC='\033[0m'
if git rev-parse --verify HEAD >/dev/null 2>&1
@johnnyji
johnnyji / JavaScript
Created July 25, 2015 21:55
It's Party Time
var sys = require("sys");
var exec = require('child_process').exec;
var five = require('johnny-five');
var board = new five.Board();
function puts(err, stdout, stderr) { sys.puts(stdout) };
board.on('ready', function() {
console.log("board ready");
var button = new five.Button(5);
@johnnyji
johnnyji / partytime.js
Created July 25, 2015 21:56
It's Party Time
var sys = require("sys");
var exec = require('child_process').exec;
var five = require('johnny-five');
var board = new five.Board();
function puts(err, stdout, stderr) { sys.puts(stdout) };
board.on('ready', function() {
console.log("board ready");
var button = new five.Button(5);
@johnnyji
johnnyji / codemod-add-semicolon.js
Last active April 14, 2018 16:48
Codemod for Babel 6 Semicolon Requirement
module.exports = function (file, api) {
var j = api.jscodeshift;
var root = j(file.source);
// Finds the all classes that have properties
root
.find(j.ClassDeclaration, {
body: {
type: 'ClassBody',
body: [{
@johnnyji
johnnyji / .vimrc
Created March 21, 2016 16:24
My .vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable Pathogen
execute pathogen#infect()
syntax on
" Enable filetype plugins
filetype plugin on
filetype indent on
@johnnyji
johnnyji / anon-function-in-react.js
Created January 16, 2018 22:10
Dirty Anon React Component
class Main extends React.Component {
// ...
render() {
// We should NEVER pass anonymous functions as props to React components unless
// we absolutely need to.
//
// Anonymous functions are redefined on every render cycle, which means
// the function you pass to your child component is different every time.
//
// ...
render() {
return (
<div>
<Button
label='Click me to increment!'
onClicked={() => { this.setState({count: this.state.count + 1}) }}
/>
<Button
// ...
render() {
return (
<div>
<Button
label='Click me to increment!'
onClicked={this._handleIncrementView}
/>
<Button
class Main extends React.Component {
// ...
render() {
// Because we've named the prop `this._handleClick`, we're now passing a FUNCTION REFERENCE and
// no longer creating a new function on every render cycle. The function reference will not change throughout
// the lifecycle of `Main`, therefore it will never cause `Button` to re-render.
return (
<div>
<p>This button has been clicked {count} times</p>