Skip to content

Instantly share code, notes, and snippets.

View sfengyuan's full-sized avatar
🎯
Focusing

sunfy sfengyuan

🎯
Focusing
  • China
View GitHub Profile
@sfengyuan
sfengyuan / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sfengyuan
sfengyuan / httpd-vhosts.conf
Last active December 2, 2015 05:54
Apache Setting
<VirtualHost localhost:80>
DocumentRoot "default/site/directory"
ServerName localhost
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost mysite.loc:80>
DocumentRoot "mysite/path"
ServerName mysite.loc
@sfengyuan
sfengyuan / MY_form_helper.php
Last active January 13, 2016 08:07
Codeigniter csrf token helper
// In codeigniter, form_open() can automatic output a csrf token field.
// But, I prefer use the html form tag.
// This function can manually insert a token to form elements.
function csrf_token()
{
$CI = & get_instance();
$hidden[$CI->security->get_csrf_token_name()]= $CI->security->get_csrf_hash();
$form_token = sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
echo $form_token;
}
@sfengyuan
sfengyuan / config.php
Created January 31, 2016 11:50 — forked from vzool/config.php
CodeIgniter: ignore CSRF in many URIs
// Put those lines in application/config/config.php
$csrf_ignore = [
'/page1.html',
'/about.html'
];
$is_csrf_condition_met = true;
foreach($csrf_ignore as $ci){
@sfengyuan
sfengyuan / Open with
Last active August 25, 2022 10:34
Settings on Windows: open with sublime text and vs code, scoop python registry entries
@echo off
SET AppKey=SublimeText3
SET AppTitle=Sublime Text 3
SET AppPath=D:\Program Files\st\sublime_text.exe
SET AppIcon=%AppPath%,0
REG ADD "HKEY_CLASSES_ROOT\*\shell\%AppKey%" /ve /f /d "%AppTitle%"
REG ADD "HKEY_CLASSES_ROOT\*\shell\%AppKey%" /v "Icon" /f /d "%AppIcon%"
REG ADD "HKEY_CLASSES_ROOT\*\shell\%AppKey%\command" /ve /f /d "%AppPath% \"%%1\""
@sfengyuan
sfengyuan / numbers.js
Created October 11, 2017 06:10
Javascript
function round(value, decimals) {
return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}
//round(1.005, 2);
// 1.01
@sfengyuan
sfengyuan / .gitignore
Created October 20, 2017 17:31
gitignore for frontend project
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
*.cache
# dependencies
node_modules
@sfengyuan
sfengyuan / sync.bat
Created December 19, 2017 05:38
Sync sublime text, vs code, cmder with dropbox on windows
:: Ensure the two sublime text folders are moved into drobox first.
:: Sublime text uses links to work.
mklink /j "D:\Program Files\st3\Data\Packages" "E:\Dropbox\st\Data\Packages"
mklink /j "D:\Program Files\st3\Data\Installed Packages" "E:\Dropbox\st\Data\Installed Packages"
:: Dropbox uses links to sync vs code.
:: In vs code, custom keymap should be done with keybindings.json, otherwise they won't be saved to dropbox.
mklink /j "E:\Dropbox\code\User" "%appdata%\Code\User"
mklink /j "E:\Dropbox\code\.vscode" "%USERPROFILE%\Code\.vscode"
@sfengyuan
sfengyuan / insertText.js
Created December 19, 2017 08:30
Insert text to textarea
/**
* Insert <text> to <areaId>, then [selectedText] will be selected.
*
* @export module.insertAtCaret
* @param {string} areaId - ID of textarea
* @param {string} text - text to be inserted
* @param {string} [selectedText=undefined] - a sub string of param <text>,
* will be selected after insertion, and also be replaced by the current selected text in textarea
*/
export function insertAtCaret (areaId, text, selectedText = undefined) {
@sfengyuan
sfengyuan / .babelrc
Last active June 15, 2018 06:21
js config
{
"presets": [
[
"env",
{"modules": false}
],
["stage-3"]
],
"plugins": ["transform-runtime"],
"env": {