Skip to content

Instantly share code, notes, and snippets.

Huafu Gandon huafu

Block or report user

Report or block huafu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@huafu
huafu / clone.ts
Created Jul 18, 2018
JavaScript real object clone
View clone.ts
export default function clone<T>(base: T): T {
const res = Object.create(base.constructor.prototype)
Object.defineProperties(res, Object.getOwnPropertyDescriptors(base))
return res
}
@huafu
huafu / a.ts
Last active Jun 15, 2018
Issue with firebase typings when sharing code between frontend and backend
View a.ts
// INFO: this has been simplified a maximum just to show the underlying issue
import { database as rtdbClient } from 'firebase'
import { database as rtdbServer } from 'firebase-admin'
type Database = rtdbClient.Database | rtdbServer.Database
type DataSnapshot = rtdbClient.DataSnapshot | rtdbServer.DataSnapshot
interface User {
id: string
@huafu
huafu / lvimg.sh
Created Dec 15, 2015
Backup of LVM logical volume by creating a gzip compressed image of temporary snapshot
View lvimg.sh
#!/bin/bash
# usage:
# lvimg lv_dev [backup_path]
#
# lv_dev: path to the logical volume to backup
# backup_path: optional, base path of backups (default to /mnt/backups)
# config
DEFAULT_BACKUP_PATH="/mnt/backups"
@huafu
huafu / gist:b34ad7062dc7f09cd80b
Created Jun 16, 2015
Ralink Technology, Corp. RT2870/RT3070 Wireless Adapter not recognized as a wifi card in OpenWrt 15.05-r2 on a RaspBerry B+
View gist:b34ad7062dc7f09cd80b

I have a fresh install of OpenWrt 15.05-rc2 on a RaspBerry B+

root@bnh-traveller:~# uname -a
Linux bnh-traveller 3.18.11 #1 Mon May 18 21:56:20 CEST 2015 armv6l GNU/Linux

I have already installed required packages with success

root@bnh-traveller:~# opkg install kmod-rt2800-lib kmod-rt2800-usb kmod-rt2x00-lib kmod-rt2x00-usb  
Package kmod-rt2800-lib (3.18.14+2015-03-09-3) installed in root is up to date.
View app_initializers_session-service.js
export function initialize(container, application) {
application.inject('service:session', 'store', 'store:main');
application.inject('route', 'session', 'service:session');
application.inject('controller', 'session', 'service:session');
application.inject('model', 'session', 'service:session');
application.inject('component', 'session', 'service:session');
application.deferReadiness();
// load the current session
container.lookup('service:session').load().then(function () {
application.advanceReadiness();
@huafu
huafu / search-icon.html
Created Dec 24, 2014
HTML search icon (magnifier)
View search-icon.html
<span style="display: inline-block;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);">
&#9906;
</span>
View index.html
<script type="text/x-handlebars" data-template-name="index">
{{each itemView='dummy'}}
</script>
<script type="text/x-handlebars" data-template-name="dummy">
IN DUMMY TEMPLATE
{{view.val}} {{t}}
</script>
@huafu
huafu / with-style.js
Created Oct 23, 2014
Add a `styleBindings` property to views which can be used like `attributeBindings`. Support units as well.
View with-style.js
import Ember from 'ember';
/**
* @mixin WithStyleMixin
*/
var WithStyleMixin = Ember.Mixin.create({
concatenatedProperties: ['styleBindings'],
attributeBindings: ['style'],
/**
@huafu
huafu / logger.coffee
Created Oct 21, 2014
Very simple logger to instrument objects and methods
View logger.coffee
logger =
_anonymousIndex: 0
guessMethodName: (method) ->
unless (res = (->).toString.call(method).match(/function([^\(]*)/)[1].replace(/(^\s+|\s+)$/g, ''))
res = logger.autoNamespace()
res
autoNamespace: ->
"[anonymous##{ ++logger._anonymousIndex }]"
@huafu
huafu / application.js
Created Oct 7, 2014
Application ficture adapter with queryFixtures implementing limits, order and filters (requires momentjs)
View application.js
import Ember from 'ember';
import DS from 'ember-data';
function hasOwn(o, p) {
return {}.hasOwnProperty.call(o, p);
}
function castId(r) {
return '' + (r && r instanceof DS.Model ? r.get('id') : r);
}
You can’t perform that action at this time.