From baca60b2eecdafe848acbac54a330f3b29388e71 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Thu, 11 Oct 2012 16:13:19 +0800 Subject: [PATCH] Massive update. --- bash.md | 7 +++- canvas.md | 58 ++++++++++++++++++++++++++++++++ css.md | 39 ++++++++++++++++++++- fitness.md | 10 ++++++ html.md | 5 +++ javascript.md | 43 ++++++++++++++++++++++++ linux.md | 5 +++ makefile.md | 41 +++++++++++++++++++++-- postgresql.md | 4 +++ rails-helpers.md | 77 ++++++++++++++++++++++++++++++++++++++++++ rails-migrations.md | 5 +++ rails-models.md | 24 +++++++++---- sass.md | 28 +++++++++++++++- stylus.md | 82 +++++++++++++++++++++++++++++++++++++++++++++ tig.md | 2 ++ vim.md | 24 +++++++++---- vows.md | 50 +++++++++++++++++++++++++++ 17 files changed, 486 insertions(+), 18 deletions(-) create mode 100644 canvas.md create mode 100644 javascript.md create mode 100644 postgresql.md create mode 100644 rails-helpers.md create mode 100644 stylus.md create mode 100644 vows.md diff --git a/bash.md b/bash.md index 27d6937e4..194bf1426 100644 --- a/bash.md +++ b/bash.md @@ -1,6 +1,11 @@ title: Bash --- +### Clever one liners + + # Search and replace in all files + perl -p -i -e "s/from/to/g" **/*.css + ### String substitutions by patterns STR=/path/to/foo.c @@ -31,7 +36,7 @@ title: Bash for i in /etc/rc.*; do echo $i - end + done ### Reading input diff --git a/canvas.md b/canvas.md new file mode 100644 index 000000000..55ddd8737 --- /dev/null +++ b/canvas.md @@ -0,0 +1,58 @@ +### Getting the context + + var canvas = document.getElementById('c'); + var c = canvas.getContext("2d"); + +### Basic drawing + + // x = 10, y = 20, width = 200, height = 100 + c.fillStyle = '#ff0000'; + c.strokeStyle = '#ff00ff'; + c.lineWidth = 5; + c.lineCap = 'round'; + c.fillRect(10, 20, 200, 100); + c.stroke(); + +### Image drawing + + c.drawImage(image, dx, dy, [dw, dh]); + /* `image` can be HTML Image/Canvas/Video */ + +### Colors, styles shadows + + c.strokeStyle = '#ff00ff'; + c.fillStyle = '#ff00ff'; + + c.shadowOffsetX = 0; + c.shadowOffsetY = 0; + c.shadowOffsetBlur = 3.0; + c.shadowColor = 'rgba(0,0,0,0.2)'; + +### Gradients + + gr = c.createLinearGgadient(x0,y0,x1,y1) + gr = c.createRadialGradient(x0,y0,r0,x1,y1,r1) + pat = c.createPattern(image, 'repeat-x') + + c.fillStyle = gr + +### Drawing + + c.beginPath() + c.moveTo(x,y) + c.lineTo(x,y) + c.quadraticCurveTo(cpx,cpy,x,y) + c.bezierCurveTo(cp1x,cp1y,cp2x,cp2y) + c.arcTo(...) + c.arc(...) + c.closePath() + +### Text + + + +### Resources + + * [Canvas Cheatsheet PDF][cc] +[cc]: http://www.nihilogic.dk/labs/canvas_sheet/HTML5_Canvas_Cheat_Sheet.pdf + diff --git a/css.md b/css.md index dc8ef8ade..0c0b411a6 100644 --- a/css.md +++ b/css.md @@ -7,7 +7,10 @@ Webkit extensions ### Font smoothing /* maxvoltar.com/archive/-webkit-font-smoothing */ - html { -webkit-font-smoothing: antialiased; } + * { + text-rendering: optimizeLegibility !important; + -webkit-font-smoothing: antialiased !important; + } ### Heading kerning pairs and ligature @@ -28,3 +31,37 @@ Webkit extensions /* http://www.webkit.org/blog/85/introducing-text-stroke/ */ -webkit-text-stroke: 3px black; + +### iOS Scrolling prevention + + document.ontouchstart = (e) -> + $pane = $(e.target).closest('.scrollable>div') + if $pane.length is 0 or $pane[0].scrollHeight <= $pane.innerHeight() + e.preventDefault() + + %ios-scrollable + &, >div + -webkit-overflow-scrolling: touch + overflow: auto + + >div + position: absolute + top: 0 + left: 0 + right: 0 + bottom: 0 + +### UIWebView optimizations + + /* http://www.bitsandpix.com/entry/ios-webkit-uiwebview-remove-tapclick-highlightborder-with-css/ */ + + * { + -webkit-tap-highlight-color: rgba(0,0,0,0); + -webkit-user-select: none; /* disable text select */ + -webkit-touch-callout: none; /* disable callout, image save panel (popup) */ + -webkit-tap-highlight-color: transparent; /* "turn off" link highlight */ + } + + a:focus { + outline:0; // Firefox (remove border on link click) + } diff --git a/fitness.md b/fitness.md index 01aa5206e..73873d213 100644 --- a/fitness.md +++ b/fitness.md @@ -44,3 +44,13 @@ Jennifer Thompson video: http://www.youtube.com/watch?v=34XRmd3a8_0 intense exercise (>70% VO2 max) primarily utilized carbohydrate. http://www.exrx.net/Nutrition/Substrates.html + +### Deloads on a cut + + - "I would never recommend traditional style deloads on a cut, regardless of + training regimen." + + - "increase the rest day interval between sessions" + +https://www.facebook.com/permalink.php?story_fbid=273265046115238&id=116211138487297&comment_id=1262284&offset=0&total_comments=34 + diff --git a/html.md b/html.md index 300df70e2..22a6f1187 100644 --- a/html.md +++ b/html.md @@ -9,6 +9,11 @@ title: HTML +### IE conditionals + + + Not IE + ### iPhone viewport diff --git a/javascript.md b/javascript.md new file mode 100644 index 000000000..2ed9e1252 --- /dev/null +++ b/javascript.md @@ -0,0 +1,43 @@ +## Web workers + + // Client code + + var worker = new Worker('worker.js'); + worker.onmessage = function(message) { + alert(message.data); + }); + worker.postMessage(""); + +### Worker code + + // worker.js + + self.onmessage = function(message) { + alert(message.data); + } + self.postMessage(""); + +### Message data + + // [MessageEvent] + bubbles: false + cancelBubble: false + cancelable: false + clipboardData: undefined + currentTarget: Worker + data: "Hello" + defaultPrevented: false + eventPhase: 0 + lastEventId: "" + origin: "" + ports: Array[0] + returnValue: true + source: null + srcElement: Worker + target: Worker + timeStamp: 1344821022383 + type: "message" + + + + diff --git a/linux.md b/linux.md index 635f560dc..152009d2a 100644 --- a/linux.md +++ b/linux.md @@ -2,3 +2,8 @@ $ mount -t tmpfs -o size=5G,nr_inodes=5k,mode=700 tmpfs /tmp +### Visudo + + sudo visudo + + username ALL=(ALL) NOPASSWD:/sbin/restart whatever diff --git a/makefile.md b/makefile.md index 0343060f3..195b9eccf 100644 --- a/makefile.md +++ b/makefile.md @@ -1,17 +1,53 @@ -### Safe assignment +### Var assignment + JS_COMPRESSOR := $(uglify) + + # Safe assignment prefix ?= /usr/local +### Magic variables + + $^ -- dependencies + $@ -- the thing to be built + + $@ -- Rule target + $% -- Target member name ('foo' in 'foo.c' for '%.c') + $^ -- Prerequisites (all, without duplication) + $+ -- Prerequisites (all, with duplication) + $? -- Prerequisites (new ones) + $| -- Prerequisites (order-only?) + $< -- Prerequisite (first) + $* -- Basename without extension of the target (?) + ### Cool stuff gitdir ?= $(shell git --exec-path) gitver ?= $(word 3,$(shell git --version)) +### Find files + + FILES = $(shell find images -name "*") + + $(patsubst images/%, assets/%, $(shell find images -name "*")) + ### Substitutions + # Same $(SOURCE:.cpp=.o) $(patsubst %.cpp, %.c, $(SOURCES)) + $(strip $(string_var)) + + $(filter %.less, $(files)) + $(filter-out %.less, $(files)) + +### Executing + + JS_COMPRESSOR := $(uglify) + + docs: + $(JS_COMPRESSOR) file.js + ### Building files %.o: %.c @@ -22,5 +58,4 @@ default: @echo "hello." - @false - + @false diff --git a/postgresql.md b/postgresql.md new file mode 100644 index 000000000..581858720 --- /dev/null +++ b/postgresql.md @@ -0,0 +1,4 @@ + + * Show tables: `\dt` + * Show databases: `\l` + * Show columns of a table: `\d table` or `\d+ table` diff --git a/rails-helpers.md b/rails-helpers.md new file mode 100644 index 000000000..287158eba --- /dev/null +++ b/rails-helpers.md @@ -0,0 +1,77 @@ +title: Rails helpers +--- + +### Date helpers + +http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html + +### Date + + distance_of_time_in_words(Time.now, project.end_date) #=> 3 hours + distance_of_time_in_words_to_now project.end_date #=> 3 hours + +### Time select + + # Creates a time select tag that, when POSTed, will be stored in the article + # variable in the sunrise attribute. + time_select "article", "start_time" + + # All options are optional + time_select "article", "start_time", \ + :include_seconds => true, + :minute_step => 15, + :prompt => true, + :prompt => { :hour => "Choose hr", :minute => "Choose min", :second => "Choose sec" }, + :ampm => true + + # For dates (all options are optional) + date_select "article", "written_on", \ + :start_year => 1995, + :use_month_numbers => true, + :discard_day => true, + :include_blank => true, + :order => [:day, :month, :year], + :default => 3.days.from_now, + :default => { :day => 20 }, + :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' } + +### Time tag + + time_tag Date.today #=>