Skip to content

Instantly share code, notes, and snippets.

@ghsyeung
ghsyeung / ShutdownListener.java
Created February 22, 2012 17:45
Webapp clean-up
public class ShutdownListener implements ServletContextListener {
@Override
public void contextDestroyed(ServletContextEvent sce) {
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
P p = (P) ctx.getBean("proc");
p.shutdown();
}
}
@ghsyeung
ghsyeung / gist:1905475
Created February 25, 2012 02:51
Multi-dimensional Array Initilization
k = 1
r = 3
c = 5
# Correct way
A = [[ k ] * c for i in range(r)]
A[0][3] = 0
#>>> A
#[[1, 1, 1, 0, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]
@ghsyeung
ghsyeung / gist:1906078
Created February 25, 2012 03:41
Reverse a string
a = "12345"
# a[i:j:k] from i to j in steps k
s = a[::-1]
print s
# '54321'
@ghsyeung
ghsyeung / config.ru
Created March 5, 2012 22:04
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
@ghsyeung
ghsyeung / controller-spec.rb
Created March 21, 2012 03:13
Starting a RoR project
require 'spec-helper'
describe UserController do
describe "Search user with name" do
it "should respond to search user route"
it "should call User model method to search user with same name"
it "should show view with the list of matching users" do
response.should render_template("matching_users")
it "should redirect to index page if not found" do
response.should redirect_to(:action => )
@ghsyeung
ghsyeung / gist:2559116
Created April 30, 2012 15:11
Oracle useful commands
select default_tablespace, temporary_tablespace
from dba_users
where username = 'g'
select sum(bytes) from dba_segments where owner='g'
select * from dba_segments where owner='g'
select * from dba_segments where owner='g'
select * from dba_free_space where tablespace_name = 'USERS' order by bytes desc
ALTER TABLESPACE USERS ADD DATAFILE '/oracle/product/11.1.0/oradata/ORA11G/users02.dbf' SIZE 5242880 AUTOEXTEND ON NEXT 268435456 MAXSIZE 65535M
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@ghsyeung
ghsyeung / designer.html
Last active August 29, 2015 14:12
designer
<link rel="import" href="../yt-video/yt-search-video.html">
<polymer-element name="my-element">
<template>
<style>
#yt_search_video {
width: 300px;
height: 300px;
left: 350px;
@ghsyeung
ghsyeung / gulp-compile.js
Last active August 29, 2015 14:19
Typescript hands on
gulp.src(sourceTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc({
target: 'ES5',
declarationFiles: false,
noExternalResolve: true,
typescript: require('typescript') // Only required if you override the default typescript dependency
}));
> tsd install firebase --save # Install the firebase definition
> tsd reinstall # Reinstall according to tsd.json