Skip to content

Instantly share code, notes, and snippets.

View imikay's full-sized avatar
💭
I may be slow to respond.

Ian Gao imikay

💭
I may be slow to respond.
  • Mikay Inc.
  • Shanghai, China
View GitHub Profile
@imikay
imikay / gist:0f9f0d71e613848ee647cd4d543e3d49
Last active January 23, 2022 14:16
Pass array/list data to Spring with axios

That's one way to do this, on Spring side

@PostMapping("api/user")
public Response theAction(@RequestBody List<User> users)

on the javascript side,

@imikay
imikay / gist:26868a9d7af1940fe9d8
Created January 27, 2016 12:09
Tampermonkey script
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://app.meiqia.com/chat/*
// @grant none
// ==/UserScript==
/* jshint -W097 */
1. overflow: hidden only works on positioned elements.
2. display: inline-block; hack:
display: inline-block;
*display: inline;
*zoom: 1;
3. IE 7 float: right; drop to new line:
Try to small change markup: place items with a float before items without it (from the same row). It should help.
@imikay
imikay / gist:a0487aecbde27a3d4b12
Last active March 27, 2019 08:36
Simple js template engine
function render(template, vars)
{
for (var v in vars)
{
var pattern = '{{' + v + '}}';
template = template.replace(new RegExp(pattern, 'gi'), vars[v]);
}
return template;
};
@imikay
imikay / promises.md
Created October 22, 2012 05:35 — forked from domenic/promises.md
You're Missing the Point of Promises

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
    // the rest of your code goes here.
});
@imikay
imikay / Symfony command
Created October 17, 2012 08:03
Windows command for Symfony to avoid typing php app/console every time.
@echo off
pushd .
cd %~dp0
cd "app"
set BIN_TARGET=%CD%\console
popd
php "%BIN_TARGET%" %*
@imikay
imikay / Gemfile
Created September 14, 2012 05:54
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@imikay
imikay / API design
Created April 4, 2012 12:05
API design
The data returned from an API should have a similar structure like the following:
Success:
{status: 1, data: [A collection of data]}
Error:
{status: 0, error: { code: 1, message: 'critical error' }}
And the data returned must always have a consistent structure, for example, an image API
should always return a data structure like this: {title: A fancy image, link: http://www.example.com},
@imikay
imikay / querylet.js
Created February 7, 2012 08:31
Querylet
javascript:
(function (window, document)
{
var rLeftTrim = /^\s+/;
var rRightTrim = /\s+$/;
var prom = prompt('Please input order number');
var cleaned = prom.replace(rLeftTrim, '').replace(rRightTrim, '');
@imikay
imikay / getElementPosition.js
Created December 18, 2011 10:47
Get an element's position using JS
function getElementPosition(element)
{
var x = element.offsetLeft;
var y = element.offsetTop;
var parent = element;
while (parent = parent.offsetParent)
{
x += parent.offsetLeft;