Skip to content

Instantly share code, notes, and snippets.

@jooeycheng
jooeycheng / special_sort.rb
Last active July 3, 2016 19:40
Function that rearranges an array of positive integers to produce largest possible integer when concatenated
# === Program
class Main
def compare(n1, n2)
(n1 + n2).to_i > (n2 + n1).to_i
end
def special_sort(arr)
result = []
temp = []
@jooeycheng
jooeycheng / equilibrium_index.rb
Last active July 4, 2016 06:36
Function that finds the equilibrium index of an array
# === Program v1 [time complexity: O(n^2)]
class Main
def equilibrium_index(arr)
result = []
arr.each_with_index do |el, i|
j = 0
sum_prefix = 0
@jooeycheng
jooeycheng / codility_lessons.rb
Last active July 5, 2016 09:27
Solutions to some of Codility Lessons
# === [Lesson 2: Arrays] - CyclicRotation
# === Program v1 (recursive)
def solution(a, k)
return a if k == 0 || a.length == 0
a = a.unshift(a.delete_at(a.length - 1))
k -= 1
return solution(a, k)
end
@jooeycheng
jooeycheng / .bashrc
Created August 26, 2016 04:45
custom ubuntu bash prompt
# custom bash, copied from Vagabond box
bind 'set completion-ignore-case on'
GIT_PS1_SHOWDIRTYSTATE=1 # displays * or +
GIT_PS1_SHOWSTASHSTATE=1 # displays $
GIT_PS1_SHOWUNTRACKEDFILES=1 # displays %
GIT_PS1_SHOWUPSTREAM='auto' # displays <, >, <> or =
GIT_PS1_SHOWCOLORHINTS=1
GIT_PS1_DESCRIBE_STYLE='contains'
RESET="\[\033[0m\]"
GRAY="\[\033[38;5;248m\]"
@jooeycheng
jooeycheng / git_notes.md
Last active September 1, 2016 10:59
jooeycheng git notes / reference / cheatsheet
git status
git diff                        // diff working_dir vs last_commit

git log
git log --graph                 // visualize graph topology in terminal
gitk                            // visualize graph topology in gitk (GUI)

git add .                       // stage new & modified files, without deleted
git add -u                      // stage modified & deleted files, without new
@jooeycheng
jooeycheng / Open in iTerm
Created December 10, 2016 07:48
Open in iTerm AppleScript
-- Adapted from:
-- https://gist.github.com/eric-hu/5846890
--
-- Modified to work with files as well, cd-ing to their container folder
on run {input, parameters}
tell application "Finder"
set my_file to first item of input
set filetype to (kind of (info for my_file))
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer:
-- http://stackoverflow.com/a/6881524/640517
@jooeycheng
jooeycheng / multiplexer.js
Last active January 18, 2017 03:03
ExpressJS Multiplexer
var express = require('express')
var app = express()
var request = require('request')
app.use(require('body-parser').json())
var endpoints = require('./endpoints.json')
var response = require('./response.json')
app.all("*", function(req, res) {
endpoints.forEach(function(ept) {
full_url = ept + req.url
@jooeycheng
jooeycheng / localtunnel.rb
Last active October 26, 2017 08:48
Ruby auto-restart script for localtunnel
# https://github.com/localtunnel/localtunnel/issues/81#issuecomment-218320442
# usage: ruby localtunnel.rb --port 3000 --subdomain yourdomainhere
require 'optparse'
options = { subdomain: 'defaultdomain', port: 3000 }
parser = OptionParser.new do |opts|
opts.banner = 'Usage: localtunnel.rb [options]'
opts.on('-s', '--subdomain subdomain', 'Subdomain') do |subdomain|
@jooeycheng
jooeycheng / Awesome Free Apps.md
Last active June 24, 2020 03:43
Awesome Free Web Apps (No Logins)
@jooeycheng
jooeycheng / ReactComponentSample.js
Last active June 24, 2020 03:55
Example React Component (cheatsheet)
/**
* Sample Component file for reference, because Joey forgets simple stuff.
*/
import React from 'react';
import './Sample.scss';
class Sample extends React.Component {
constructor(props) {
super(props);