Skip to content

Instantly share code, notes, and snippets.

View hamxiaoz's full-sized avatar

Andrew Zheng hamxiaoz

View GitHub Profile
@hamxiaoz
hamxiaoz / olv.cs
Created February 16, 2016 18:46
Ultra fast real-time data display in ObjectListView
View olv.cs
// Refresh the data in timer or in live data update callback
this.timer.Tick += (s, e) => {
// draw the live value
using (Graphics g = this.dataListView1.CreateGraphics())
{
// shrink the drawing area so that the grid line and selection color can be seen.
Rectangle r = lvi.GetSubItem(4).Bounds;
r.Inflate(-2, -2);
// use double buffer to avoid flicker
@hamxiaoz
hamxiaoz / meteor_crud_basic.coffee
Last active February 8, 2019 12:58
Meteor CRUD form with AutoForm: tab and editor style
View meteor_crud_basic.coffee
# jade
template(name='productNumbersCrud')
h4 Product Numbers
.row
.col-md-6
table.tabel.table-hover.table-striped.table-bordered
tbody
each productNumbers
tr
td
@hamxiaoz
hamxiaoz / point-free.ts
Last active February 22, 2018 00:39
Point free style in TypeScript
View point-free.ts
interface Transaction {
amount: number;
}
class Test {
private const BIG_AMOUNT = 10;
public getPositiveTransactions(transactions: Transaction[]) {
// point free
return transactions.filter(this.isPositive);
View NgModule-template.js
@NgModuel({
imports: [], // Import other module
declarations: [], // The components, directives and pipe belong to this module
providers: [], // Provide service (class name) that's defined in **this** module. External service is not needed here.
exports: [], // Export **declarable** classes so that other module can use. This is the public API of the component..
entryComponents: [], // A list of components that are not referenced in a reachable component template in this moodule.
bootstrap: [] // Usually root component.
})
export class AppModule { }
@hamxiaoz
hamxiaoz / crontab
Last active March 8, 2016 17:54
Use git to backup MongoDB for Meteor
View crontab
# run every day at 12am
00 00 * * * /home/x/run_backup.sh
@hamxiaoz
hamxiaoz / isxdl.cs
Last active February 17, 2016 23:34
How to use [isxdl.dll](http://woohaeng.com.ne.kr/docs/isxdl.htm) to download files in C#?
View isxdl.cs
[DllImport("isxdl.dll")]
static extern Int32 isxdl_Download(IntPtr hWndParent, String pszURL, String pszFileName);
[DllImport("isxdl.dll")]
static extern Int32 isxdl_SetOption(String option, String value);
private void button_download_Click(object sender, EventArgs e)
{
var fileUrl = "REPLACE_ME";
@hamxiaoz
hamxiaoz / save.js
Created July 26, 2015 16:41
A way to generate and download CSV files client-side
View save.js
// https://github.com/mholt/PapaParse/issues/175
var blob = new Blob([csvString]);
if (window.navigator.msSaveOrOpenBlob) // IE hack; see http://msdn.microsoft.com/en-us/library/ie/hh779016.aspx
window.navigator.msSaveBlob(blob, "filename.csv");
else
{
var a = window.document.createElement("a");
a.href = window.URL.createObjectURL(blob, {type: "text/plain"});
a.download = "filename.csv";
document.body.appendChild(a);
@hamxiaoz
hamxiaoz / CoffeeScript
Last active August 29, 2015 14:23
In place edit in Meteor using template instance and afterFlush
View CoffeeScript
Template.imageDescription.onCreated ->
template = this
# template level instance
template.editing = new ReactiveVar(false)
template.saving = new ReactiveVar(false)
# Automatically focus the input
Tracker.autorun ->
editing = template.editing.get()
if editing
@hamxiaoz
hamxiaoz / gist:d3029c9fba8d0faaaa0d
Created December 3, 2014 19:40
Datatables init
View gist:d3029c9fba8d0faaaa0d
$('#channels-table').dataTable
scrollX: true
scrollY: '600px'
scrollCollapse: true
paging: false
destroy: true
dom: 'lrtip' # remove filter but keep 'searching' option in order to make column filter work
# table row select effect
$('#channels-table tbody tr').on 'click', (e)->
@hamxiaoz
hamxiaoz / UI events
Last active August 29, 2015 14:02
Helpers or Utilities I used in Meteor.js project
View UI events
// https://github.com/hharnisc/meteor-accounts-admin-ui-bootstrap-3/blob/bc613e55d4e8c9b419b798e92d274dc697d68b15/client/accounts_admin.js#L35
// search no more than 2 times per second
var setUserFilter = _.throttle(function(template) {
var search = template.find(".search-input-filter").value;
Session.set("userFilter", search);
}, 500);
Template.accountsAdmin.events({
'keyup .search-input-filter': function(event, template) {