Skip to content

Instantly share code, notes, and snippets.

@piglovesyou
piglovesyou / test.js
Created January 24, 2012 07:04
テストgist
# Minify script for production use.
task 'minify', 'Minify script.', (options) ->
muffin.run
files: './**/*'
options: options
map: '(jquery.flickgal).js': (matches) ->
q = muffin.readFile matches[0]
Q.when q, (result) ->
if _.isString result
a = result.match(/\/\*[\s\S]+?\*\//)
@piglovesyou
piglovesyou / Cakefile
Created January 25, 2012 14:37
Cakefile using muffin.js (the way of `q' use, pathetic..)
# Include required libraries.
muffin = require 'muffin'
Q = require 'q'
_ = require 'underscore'
temp = require 'temp'
tempdir = temp.mkdirSync()
@piglovesyou
piglovesyou / gist:4238321
Created December 8, 2012 02:45
quicksort in Javascript
/**
* @param {Array} array .
* @return {Array} A sorted array.
*/
function quicksort(array) {
if (array.length === 0) return array;
var pivot = array.splice(0, 1)[0],
left = [],
right = [],
@piglovesyou
piglovesyou / gist:4239149
Created December 8, 2012 07:37
Create literal vs use static
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
var obj = {
yeah: 'yeah',
ohh: 'ohh'
};
@piglovesyou
piglovesyou / gist:7478087
Created November 15, 2013 02:19
Style input[placeholder]
/* http://stackoverflow.com/questions/2610497/change-an-inputs-html5-placeholder-color-with-css */
/* http://jsfiddle.net/Sk8erPeter/KyVXK/ */
/* Must define separately */
::-webkit-input-placeholder {
color: red;
}
:-moz-placeholder {
color: red;
}
@piglovesyou
piglovesyou / data-config.xml
Last active December 28, 2015 22:59
This is a SQLite version of a data-config.xml for https://github.com/dnephin/TracAdvancedSearchPlugin. Be aware you need a SQLite driver "org.sqlite.JDBC", which you can download from https://bitbucket.org/xerial/sqlite-jdbc and put sqlite-jdbc-X.X.X.jar in your ${SOLR_HOME}/contrib/dataimporthandler/lib/ or somewhere.
<!--
Data Import Configuration
This will load all your existing ticket and wiki data into the solr index.
If you use a database other then mysql you may need to change the queries
slightly. You will likely have to change the connection url as well.
To start this data import hit the following url (assumes solr is running
on the default port on localhost):
http://localhost:8983/solr/dataimport?command=full-import
@piglovesyou
piglovesyou / solr
Last active December 29, 2015 07:29
A Solr service script example based on http://stackoverflow.com/a/8189312/804314.
#!/bin/sh
# Service script to start|status|stop|restart Solr Server.
SOLR_HOME=/var/solr/
SOLR_LIB=/usr/local/lib/solr/
JETTY_HOME=${SOLR_LIB}example/
@piglovesyou
piglovesyou / gist:62808db1c1a2a767306a
Created July 26, 2014 06:41
slow upsert in Sails.js
module.exports = {
attributes: {
/* e.g.
nickname: 'string'
*/
},
@piglovesyou
piglovesyou / gist:50b8dbf82b31a5d2402f
Created August 28, 2014 10:59
downgrade all packages to the last state
diff --git a/downgrade_orig b/downgrade_orig
index 119221f..4577388 100644
--- a/downgrade_orig
+++ b/downgrade_orig
@@ -15,9 +15,11 @@ prompt_to_install() {
output_package "$((i++))" "$entry"
done
- printf "\n"
- gettext 'select a package by number: '; read -r ans
@piglovesyou
piglovesyou / gist:a930ea484f764ec1b9ec
Created September 23, 2014 11:58
read/write stream
var fs = require('fs');
var readable = fs.createReadStream('large.txt', {encoding: 'utf8'});
var writable = fs.createWriteStream('out.txt', {encoding: 'utf8'});
var count;
var left = '';
var reader = new Reader;
readable.on('data', function(chunk) {