Skip to content

Instantly share code, notes, and snippets.

@yigger
yigger / isPalindrome.c
Last active February 24, 2017 06:10
判断一个数是否是回文,如121 true, 133 false
/*
* 从后往前算 == 从前往后算(当数字位数是偶数 或者 0) 或者 从后往前算/10 == 从前往后算(当数字位数是奇数)
*/
bool isPalindrome(int x) {
if(x < 0 || (x != 0 && x % 10 == 0)) return false;
int sum = 0;
while(x > sum) {
sum = sum*10 + (x % 10);
x = x / 10;
}
/*
计算汉明距离,
eg:x = 4,y = 3
x:0100
y:0011
汉明距离 = 3
算法:
先算x^y = 0111
这里只需要判断有几个1,那么汉明距离就是多少
技巧
@yigger
yigger / sumOfTwoInt.c
Created March 5, 2017 15:07
计算两个数的和不用+-*/
/*递归版本
*/
int getSum(int a, int b) {
return b == 0 ? a : getSum(a^b, (a&b)<<1);
}
/*不递归版本
int getSum(int a, int b) {
int sum = a;
char findTheDifference(char* s, char* t) {
int s_sum = 0;
int t_sum = 0;
while(*s != '\0') {
s_sum += *s;
s++;
}
while(*t != '\0') {
t_sum += *t;
t++;
<?php
function getHead($urls){
$results = array();
// make sure the rolling window isn't greater than the # of urls
$rolling_window = 5;
$rolling_window = (sizeof($urls) < $rolling_window) ? sizeof($urls) : $rolling_window;
$master = curl_multi_init();
// $curl_arr = array();
@yigger
yigger / vscodeSetting.json
Created May 31, 2017 10:15
vscode setting..
// 将设置放入此文件中以覆盖默认设置
{
"editor.fontSize": 16,
"terminal.integrated.shell.linux": "/bin/zsh",
"editor.tabSize": 2,
"window.zoomLevel": 0,
"editor.minimap.enabled": true,
"workbench.iconTheme": "vs-seti",
"phpformatter.composer": true,
"[cpp]": {
@yigger
yigger / .tmux.conf
Created June 1, 2017 01:52
tmux配置
# set Zsh as your default Tmux shell
set-option -g default-shell /bin/zsh
# UTF is great, let us use that
set -g utf8
set-window-option -g utf8 on
# Tmux should be pretty, we need 256 color for that
#set -g default-terminal "screen-256color"
@yigger
yigger / index.js
Created July 27, 2018 10:36 — forked from edokeh/index.js
佛祖保佑,永无 BUG
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
" Plugins will be downloaded under the specified directory.
call plug#begin('~/.vim/plugged')
" Declare the list of plugins.
Plug 'tpope/vim-sensible'
Plug 'junegunn/seoul256.vim'
Plug 'https://github.com/vim-scripts/fcitx.vim.git'
Plug 'posva/vim-vue'