Skip to content

Instantly share code, notes, and snippets.

View hsuh's full-sized avatar
🦕

Hsu Hlaing hsuh

🦕
  • Edinburgh
  • 08:09 (UTC -12:00)
View GitHub Profile
@hsuh
hsuh / script
Last active August 29, 2015 14:02
Drawing HTML in canvas
<!DOCTYPE html>
<html >
<head>
</head>
<body>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var data = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">' +
@hsuh
hsuh / index.html
Last active August 29, 2015 14:02 — forked from mbostock/.block
Force layout with tooltips
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.geom.js?2.1.3"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.layout.js?2.1.3"></script>
<style type="text/css">
.link {
stroke: #ccc;
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?1.27.1"></script>
<style type="text/css">
div.tooltip {
position: absolute;
text-align: center;
width: 60px;
@hsuh
hsuh / gitlog
Created June 17, 2014 13:26
A better git log
Just type in:
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Or create an alias -
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
And every time you need to see your log, just type in
@hsuh
hsuh / binding
Last active August 29, 2015 14:02
Biding events to dynamically created html elements
Here is what gets you all the way:
$(document).ready(function() {
$(document).on("click","textarea",function(){
// Do something when textarea is clicked
});
});
If your app is like most web apps, it is probably full of AJAX. Suppose you have a page that renders some buttons or links but it also dynamically adds more of those elements as events happen, such as an AJAX pagination event. To top it off, all those elements have events tied to them (think hitting "Like" on a friends Facebook post that was not initially visible on the page.").
@hsuh
hsuh / screen.md
Last active October 16, 2015 18:44
screen spliting with screen

In screen the terminal multiplexer.

  • To split vertically: ctrl a then |.
  • To split horizontally: ctrl a then S (uppercase one).
  • To unsplit: ctrl a then Q (uppercase one).
  • To switch from one to the other: ctrl a then tab

Note: After splitting, you need to go into the new region and start a new session via ctrl a then c before you can use that area.

When using ng-class, the expression must evaluate to one of the following:
a string of space-delimited class names, or
and array of class names, or
a map/object of class names to boolean values.
@hsuh
hsuh / svg_foreignobj
Last active August 29, 2015 14:05
svg foreignobject
<?xml version="1.0" standalone="yes"?>
<svg xmlns = "http://www.w3.org/2000/svg" width="100%" height="100%">
<rect x="25" y="25" width="250" height="200" fill="#ff0000" stroke="#000000"/>
<foreignObject x="50" y="50" width="200" height="150">
<body xmlns="http://www.w3.org/1999/xhtml">
<form>
<input type="text"/>
<input type="text"/>
</form>
</body>
@hsuh
hsuh / gist:913bf4210e9f3f32fe4e
Created September 2, 2014 11:09
Grep colours
In your .bashrc file
export GREP_OPTIONS='--color=always'
@hsuh
hsuh / country_select_helper.rb
Created September 17, 2014 10:22
country_select fix for Rails 3.2
class CountrySelect < InstanceTag
include ::CountrySelect::TagHelper
def render(options, html_options)
@options = options
@html_options = html_options
if self.respond_to?(:select_content_tag)
select_content_tag(country_option_tags, @options, @html_options)
else