Skip to content

Instantly share code, notes, and snippets.

View nothingrealhappen's full-sized avatar
🏠
Working from home

NothingRealHappen nothingrealhappen

🏠
Working from home
  • Mars
View GitHub Profile
@nothingrealhappen
nothingrealhappen / gist:b5ee4c52db33310b89e8
Last active August 29, 2015 14:24
Functional Javascript | Recursion
/*
Recursion is a fundamental programming concept which can lead to elegant and efficient solutions to algorithmic problems. In fact, recursion is so powerful, all iterating behaviour can be defined using recursive functions. You will find recursion indispensable when iterating over nested data structures.
A recursive function is a function which calls itself. For example, this recursive function will take an array of words, and return an array of those words, uppercased.
*/
function toUpperArray(items) {
if (!items.length) return [] // end condition
var head = items[0] // item to operate on
head = head.toUpperCase() // perform action
var tail = items.slice(1) // next
$(function() {
var share = {
title: '放手放脚体验高速急刹车 9位科技大咖亲测沃尔沃自动驾驶',
desc: '全球首个自动驾驶路试项目 Drive Me Truest Me 自动驾到 谁敢来约',
link: 'http://geekpark.net/zhuanti/volvo/mobile.html',
icon: 'http://geekpark-img.qiniudn.com/volvo-guestshare.jpg'
};
(function() {
大厅里有100盏灯,每盏灯都编了号码,分别为1-100。每盏灯由一个开关来控制。(开关按一下,灯亮,再按一下灯灭。开关的编号与被控制的灯相同。)开始时,灯是全灭的。现在按照以下规则按动开关。
第一次,将所有的灯点亮。
第二次,将所有2的倍数的开关按一下。
第三次,将所有3的倍数的开关按一下。
以此类推。第N次,将所有N的倍数的开关按一下。
问第N次(N大于等于2,且小于等于100)按完以后,大厅里还有几盏灯是亮的。
请编程实现上面的逻辑,以N为参数
@nothingrealhappen
nothingrealhappen / 甘大大出的题目
Created March 31, 2015 10:51
20150331「每日一题」怕了么?
We couldn’t find that file to show.
@nothingrealhappen
nothingrealhappen / 敢来挑战一下你的智商吗?
Last active August 29, 2015 14:18
【每日一题】2015年3月31日
We couldn’t find that file to show.
@nothingrealhappen
nothingrealhappen / canvasWaterMark
Last active August 29, 2015 14:18
canvasWaterMark
真的搞不定语法高亮
doctype html
html lang="en"
head
title
| balabala....
link rel="shortcut icon" href="/favicon.ico"
meta charset='utf-8'
meta name="renderer" content="webkit"
meta http-equiv="X-UA-Compatible" content="IE=edge"
meta content='initial-scale=1.0,maximum-scale=1.0,width=device-width' name='viewport' /
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|scss|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end
@nothingrealhappen
nothingrealhappen / article2pic-remotestyle
Last active August 29, 2015 14:16
article2pic插件远程样式
[
{"selector":".article-title","value":"font-size: 12em;"},
{"selector":".article-date","value":"balabala"}
]
@nothingrealhappen
nothingrealhappen / gist:4240f6f16c3e4bee0f27
Created January 14, 2015 02:43
python模拟post脚本
#!/usr/bin/python
#coding=utf-8
import urllib
import urllib2
import random
def post(url, data):
req = urllib2.Request(url)
data = urllib.urlencode(data)