Skip to content

Instantly share code, notes, and snippets.

🙉
stack overflowed

Gerald gera2ld

🙉
stack overflowed
Block or report user

Report or block gera2ld

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
View setting-input.vue
<template>
<input v-if="ready" type="text" :class="{'has-error': error}" v-model="value">
</template>
<script>
import { debounce } from '#/common';
import options from '#/common/options';
import hookSetting from '#/common/hook-setting';
export default {
@gera2ld
gera2ld / string-util.js
Last active Dec 6, 2019
JavaScript utilities
View string-util.js
const { Readable } = require('stream');
export function string2stream(string) {
const reader = new Readable();
reader.push(string);
reader.push(null);
return reader;
}
export function escapeRegExp(string) {
@gera2ld
gera2ld / storage.js
Created Sep 30, 2019
Storage wrapper
View storage.js
export function getStorage(provider) {
return initialize();
function initialize() {
if (!provider) provider = window.localStorage;
return {
get,
set,
bind,
};
@gera2ld
gera2ld / git-update.py
Created May 18, 2019
Update all git repositories in a directory
View git-update.py
import os
import sys
import time
from queue import Queue, Empty
from threading import Thread
from git import Repo
root = sys.argv[1]
concurrency = 10
@gera2ld
gera2ld / test-violentmonkey.user.js
Last active Nov 8, 2019
Test Violentmonkey functions
View test-violentmonkey.user.js
// ==UserScript==
// @name test script
// @namespace Violentmonkey Scripts
// @icon https://cn.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
// @resource baidu https://www.baidu.com/img/baidu_jgylogo3.gif
// @resource text data:text/plain,hello,world
// @run-at document-start
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
@gera2ld
gera2ld / loadmore.js
Created Feb 17, 2017
`v-loadmore` directive for Vue.js 2
View loadmore.js
import Vue from 'vue';
import throttle from 'lodash.throttle';
Vue.directive('loadmore', {
bind(el, binding, vnode) {
let value = binding.value || {};
let callback;
if (typeof value === 'function') {
callback = value;
value = {};
@gera2ld
gera2ld / polyfill.js
Last active Feb 7, 2017
Simple polyfills for JavaScript
View polyfill.js
function polyfill(obj, key, value) {
if (!obj[key]) Object.defineProperty(obj, key, {
value,
configurable: true,
writable: true,
});
}
// Polyfill Object.assign
polyfill(Object, 'assign', (obj, ...args) => {
@gera2ld
gera2ld / gulp-rev-manifest.js
Last active Dec 1, 2016
Fix gulp-rev's bug of overwriting rev-manifest.json
View gulp-rev-manifest.js
const fs = require('fs');
const path = require('path');
const manifest = function () {
function collect() {
return through.obj(function (file, enc, cb) {
if (!file.path || !file.revOrigPath) {
return cb();
}
const revisionedFile = file.relative;
@gera2ld
gera2ld / django-context.py
Created Oct 19, 2016
Apply context for a custom view, e.g. when overriding `handler404`
View django-context.py
from django.template import loader
from django.http import HttpResponseNotFound
# The key to get through all context processors is to pass `request` to
# `template.render` as the second parameter
def not_found(request):
template = loader.get_template('not_found.html')
extra_context = {
'status': 404,
@gera2ld
gera2ld / serialize.js
Created Jun 2, 2016
Serialize an object
View serialize.js
function serialize(obj) {
if (typeof obj === 'function') {
return obj.toString();
} else if (obj === null || typeof obj !== 'object') {
return JSON.stringify(obj);
} else {
return Array.isArray(obj) ? (
'[' + obj.map(item => serialize(item)).join(',') + ']'
) : (
'{' + Object.keys(obj).map(key => JSON.stringify(key) + ':' + serialize(obj[key])).join(',') + '}'
You can’t perform that action at this time.