Skip to content

Instantly share code, notes, and snippets.

View jamesyang124's full-sized avatar

James Yang jamesyang124

View GitHub Profile

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

doctype html
| <!--[if lt IE 8 ]><html class="no-js preload lt-ie10 lt-ie9 lt-ie8 ie-suck"><![endif]-->
| <!--[if IE 8 ]><html class="no-js preload lt-ie10 lt-ie9 ie-8"><![endif]-->
| <!--[if IE 9 ]><html class="no-js preload lt-ie10 ie-9"><![endif]-->
| <!--[if gt IE 9]><!-->
html.no-js
| <!--<![endif]-->
head
meta(charset='utf-8')
meta(http-equiv='X-UA-Compatible' content='IE=edge,chrome=1')
@jamesyang124
jamesyang124 / gist:246ba6a1e455b13370e0
Created February 18, 2016 03:10 — forked from perusio/gist:1326701
Mobile device detection in Nginx with just 7 lines of configuration
### Testing if the client is a mobile or a desktop.
### The selection is based on the usual UA strings for desktop browsers.
## Testing a user agent using a method that reverts the logic of the
## UA detection. Inspired by notnotmobile.appspot.com.
map $http_user_agent $is_desktop {
default 0;
~*linux.*android|windows\s+(?:ce|phone) 0; # exceptions to the rule
~*spider|crawl|slurp|bot 1; # bots
~*windows|linux|os\s+x\s*[\d\._]+|solaris|bsd 1; # OSes
@jamesyang124
jamesyang124 / gist:03e8711093c97c185ca5
Created March 2, 2016 03:14 — forked from jessedearing/gist:2351836
Create self-signed SSL certificate for Nginx
#!/bin/bash
echo "Generating an SSL private key to sign your certificate..."
openssl genrsa -des3 -out myssl.key 1024
echo "Generating a Certificate Signing Request..."
openssl req -new -key myssl.key -out myssl.csr
echo "Removing passphrase from key (for nginx)..."
cp myssl.key myssl.key.org
openssl rsa -in myssl.key.org -out myssl.key

Memory Management and Performance

JavaScript engines such as Google’s V8 (Chrome, Node) are specifically designed for the fast execution of large JavaScript applications. As you develop, if you care about memory usage and performance, you should be aware of some of what’s going on in your user’s browser’s JavaScript engine behind the scenes.

Continue reading Writing Fast, Memory-Efficient JavaScript, great general overview of a Google employee

Videos

@jamesyang124
jamesyang124 / .gitignore
Created July 30, 2016 05:12 — forked from adamgit/.gitignore
.gitignore file for Xcode4 / OS X Source projects
#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
# Apple bugs, waiting for Apple to fix/respond:
#
# 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation?
#
# Version 2.6
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
#####
# OS X temporary files that should never be committed
.DS_Store
*.swp
*.lock
profile
#####
# DotEnv files
.env
@jamesyang124
jamesyang124 / main.go
Created March 10, 2017 10:59 — forked from sogko/main.go
[graphql-go] Mutation example with `graphql-go/handler`
package main
import (
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
"net/http"
)
type Todo struct {
ID string `json:"id"`
@jamesyang124
jamesyang124 / what-forces-layout.md
Created April 8, 2017 16:39 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@jamesyang124
jamesyang124 / Base64.md
Created May 25, 2017 08:36 — forked from barrysteyn/Base64.md
OpenSSL Base64 En/Decode: Portable and binary safe.

OpenSSL Base64 Encoding: Binary Safe and Portable

Herewith is an example of encoding to and from base64 using OpenSSL's C library. Code presented here is both binary safe, and portable (i.e. it should work on any Posix compliant system e.g. FreeBSD and Linux).

License

The MIT License (MIT)

Copyright (c) 2013 Barry Steyn