Skip to content

Instantly share code, notes, and snippets.

View AndySze's full-sized avatar
🥇
Working hard

Andy Si AndySze

🥇
Working hard
  • Earth
View GitHub Profile
├── app
│   ├── controllers
│   │   ├── center
│   │   │   ├── filter_controller.js.coffee
│   │   │   └── tickets_controller.js.coffee
│   │   ├── center_content_controller.coffee
│   │   ├── comments_controller.js.coffee
│   │   ├── header
│   │   │   └── project_nav_controller.js.coffee
│   │   ├── header_controller.coffee
#!/usr/bin/env bash
ssh linode 'cd local_clone; cd happynewsdb; \
mysqldump --extended-insert=FALSE --complete-insert=TRUE -uroot authlove_development>authlove_development.sql; \
git commit -a -m"i"; \
git push;\
cd ../happyecdb/ ; \
mysqldump --extended-insert=FALSE --complete-insert=TRUE -uroot ec_development>ec_development.sql; \
git commit -a -m"i"; \
git push;\
# install and make run basic bootstrap date-picker functionality described here http://www.eyecon.ro/bootstrap-datepicker/
# app/assets/javascript/datepicker.js.coffee
$(document).on 'pageChanged', ->
# datepicker for simple_form & Ransack
$(".custom_datepicker_selector").datepicker().on 'changeDate', (en) ->
correct_format = en.date.getFullYear() + '-' + ('0' + (en.date.getMonth() + 1)).slice(-2) + '-' + ('0' + en.date.getDate()).slice(-2) # date format yyyy-mm-dd
$(this).parent().find("input[type=hidden]").val(correct_format)

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@AndySze
AndySze / gist:5329225
Created April 7, 2013 05:52
calculate days between two dates.
#
# Given your birthday and the current date, calculate your age in days.
# Account for leap days.
#
# Assume that the birthday and current date are correct dates (and no
# time travel).
#
daysOfMonths = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def leapYear(year):
@AndySze
AndySze / gist:5329450
Last active December 15, 2015 21:59
数字到图形转换。花了较长时间才解决。类似于将数字转化为“算盘”
#########################################################################
# 10-row School abacus
# by
# Michael H
#########################################################################
# Description partially extracted from from wikipedia
#
# Around the world, abaci have been used in pre-schools and elementary
#
# In Western countries, a bead frame similar to the Russian abacus but
@AndySze
AndySze / gist:5332975
Created April 7, 2013 23:01
web crawler with depth
#
# This question explores a different way (from the previous question)
# to limit the pages that it can crawl.
#
#######
# THREE GOLD STARS #
# Yes, we really mean it! This is really tough (but doable) unless
# you have some previous experience before this course.
# A list is symmetric if the first row is the same as the first column,
# the second row is the same as the second column and so on. Write a
# procedure, symmetric, which takes a list as input, and returns the
# boolean True if the list is symmetric and False if it is not.
#
def symmetric(s):
# Your code here
i= 0
length = len(s)
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
@AndySze
AndySze / gist:5434903
Last active January 26, 2024 14:03
编译树莓派raspberry pi交叉编译工具

树莓派是基于arm内核的小电脑,性能较低,默认cpu频率为700Mhz,所以很多工作并不适合在它上面完成,比如编译软件。所以在它上面的软件需要交叉编译工具来完成。全球范围内,需要交叉编译的芯片非常多,估计超过几万种,每种芯片的编译工具又不仅相同,所以今天我来介绍交叉编译工具的编译工具(是的,很嗷口):crosstool-ng(http://crosstool-ng.org/)。它是为创建交叉编译工具而生。可以为树莓派生成可用的交叉编译工具。当然你可以去raspberry pi 官方提供的工具(http://github.com/raspberrypi/tools.git)。

1、下载ct-ng源码

到ct-ng官网(http://crosstool-ng.org/),下载源码到相应目录。

2、解压源码

tar -xjvf crosstool-ng-1.18.0.tar.bz2 

版本可能不同,请注意