Skip to content

Instantly share code, notes, and snippets.

@goooooouwa
goooooouwa / offsetFinder.c
Last active August 29, 2015 13:56
core function of the road identification algorithm
float offsetFinder(void){
int i,j;
int offset_counter = 0;
int bottom_edge_counter = 0;
float sum = 0;
//Step 1: 从摄像头获取的赛道图像的下方,向上寻找黑色赛道边界。非边界点为-1
//printf("\nedge_line:");
for(j=0;j<HORIZONTAL_PIXEL_NUM;j++){
@goooooouwa
goooooouwa / paypal_web_accept_sample_code
Last active August 29, 2015 13:57
paypal web accept sample. Notice the "notify_url" hidden form input, it's where PayPal sends IPN massage to.
<?php
$paypal_url='https://www.sandbox.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
$paypal_id='gouwa5700-facilitator@gmail.com'; // Business email ID
?>
<h4>Welcome, Guest</h4>
<div class="product">
<div class="image">
<img src="http://www.phpgang.com/wp-content/uploads/gang.jpg" />
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>HTML5 Demo: File API</title>
<link rel="stylesheet" href="css/html5demos.css">
<script src="js/h5utils.js"></script></head>
<body>
<section id="wrapper">
@goooooouwa
goooooouwa / file.js
Created May 13, 2014 06:37
simple file select input directive which watches file selected change
angular.module('file',[])
.directive('file', [function(){
return {
scope: {
file: '='
},
link: function(scope, el, attrs){
el.bind('change', function(event){
var files = event.target.files;
var file = files[0];
@goooooouwa
goooooouwa / render added style on added tenderers for the selected package.js
Created May 19, 2014 06:51
render added style on added tenderers for the selected package. This feature is useless after package selection is replaced by company search bar, since no concept of selected package any more.
$scope.companiesLoaded = function(){
angular.forEach($scope.selectedPackage.tenderers, function(tenderer, key){
var matchedCompanies = $.grep($scope.companies, function(company){ return (company.id == tenderer.company_id); });
if( matchedCompanies.length > 0){
matchedCompanies[0].selected = true;
matchedCompanies[0].added = true;
}
});
};
@goooooouwa
goooooouwa / find all companies with no contact.rb
Last active August 29, 2015 14:01
active record query to find all companies with no contact
# in English: return all companies that have a contact whose id is nil.
# why this will work is because the "includes" method will join the two tables( companies and contacts) into one table.
# for those companies who has no contacts, the record's contact is null.
Company.includes(:contacts).where(contacts: {id: nil})
@goooooouwa
goooooouwa / Create a new object from prototype.js
Last active August 29, 2015 14:02
Javascript does not have class object, what it has to allow Inheritance is prototype object, which is just another object. The way to create an new object from a prototype object is to define a constructor function for the new object and decorate the prototype property( which is an object) of the constructor function( which is also object in jav…
// 1. define a constructor function for the new object:
var objectConstructor = function(){
this.objAttr = "objAttr";
this.objMethod = function(){
alert("obj method");
}
}
// 2. decorate the prototype property of the constructor function
objectConstructor.prototype.protoAttr = "protoAttr";
@goooooouwa
goooooouwa / force_create_index
Last active August 29, 2015 14:02
command to force creating index for Elasticsearch for Rails.
# under Rails console:
ModelName.__elasticsearch__.create_index! force: true
# (optional) import your model index to Elasticsearch
ModelName.import
@goooooouwa
goooooouwa / debug_validation.rb
Created June 24, 2014 09:42
simple way to debug validations
puts "valid? #{@company.valid?}. Errors: #{@company.errors.inspect}"
@goooooouwa
goooooouwa / replace_review_and_commit.sh
Created July 25, 2014 06:15
little bash script to replace all occurrences of the first command line argument in the given directories. It will display the diff and then ask to commit.
#!/bin/bash
eval 'find app/views app/controllers app/models -type f -exec sed -i "s/ $1[^s\"]/ ConstrBase::&/g" {} \;'
eval 'find app/views app/controllers app/models -type f -exec sed -i "s/ConstrBase:: $1/ConstrBase::$1/g" {} \;'
git diff
echo -n "Here be dragons. Continue?"
read REPLY
if [[ "$REPLY" =~ ^[Yy]$ ]]
then