Skip to content

Instantly share code, notes, and snippets.

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

Prof Syd Xu bububa

💭
I may be slow to respond.
View GitHub Profile
@willwillems
willwillems / background.js
Last active June 8, 2024 21:36
Custom webpack chunk loading from a web extension (Chrome) content script.
// Throw this in your background script, it injects a generated webpack chunk when asked
chrome.runtime.onMessage.addListener(function ({ type, data}, sender, sendResponse) {
if (type === 'requestFileInjection') {
const file = data.fileName
if (!file) throw new Error('No file name provided.')
chrome.tabs.executeScript({ file: `${file}.js` }, (result) => {
console.log(`${file}.js injected`)
return sendResponse({ type: 'injected', target: { src: `${file}.js` }, success: true })
})
return true // return true so sendResponse stays valid
@tupunco
tupunco / rand.go
Last active May 2, 2018 12:29
golang Weight Rand Helper
package utils
import (
"crypto/rand"
"errors"
"math/big"
prand "math/rand"
"time"
)
@bububa
bububa / gist:2303440
Created April 4, 2012 16:18
mysql tf/idf
SELECT id, keyword, item_id, item_type, created_by, EXTRACT, extract_start, extract_end, SUM(occurrences/(SELECT keyword_count FROM keyword_counts WHERE item_id = t.item_id AND created_by = [creator user id goes here] AND item_type = t.item_type) * LOG((SELECT COUNT(1) FROM search_results)/(1+(SELECT COUNT(1) FROM search_results WHERE '.[keyword 'OR' statements go here].')))) AS keyword_density_product FROM (SELECT * FROM search_results WHERE ('.[keyword 'OR' statements go here].') AND created_by = [creator user id goes here] AND item_type = [item type, e.g. 'document', goes here]) t GROUP BY item_id ORDER BY keyword_density_product DESC LIMIT [pagination LIMIT goes here] OFFSET [pagination OFFSET goes here];
http://snipplr.com/view/51513/
@bububa
bububa / gist:1271971
Created October 8, 2011 06:58
The Procedure for Amoeba1 Server Reboot
1. stop mysql
sudo /etc/init.d/mysql stop
2. restart sphinx search
kill searched
sudo searchd /etc/sphinx/searchd.conf
3. start mongodb
sudo mongod --config /etc/mongodb/r0.conf
@fluxsaas
fluxsaas / gist:1206102
Created September 9, 2011 12:38 — forked from lightyrs/gist:1108708
lion rails 3 setup
# 2011-07-25
#
# Mac OS X 10.7
# Xcode 4.1
# Install Lion.
# Xcode
# Download Xcode from Mac App Store.
@ncweinhold
ncweinhold / snake.py
Created May 30, 2011 19:53
curses snake WIP
import curses
import time
class Direction(object):
NORTH=0
EAST=1
SOUTH=2
WEST=3
class Position(object):
@tomoconnor
tomoconnor / clientcertificate.sh
Created May 30, 2011 19:32
Create A Client Certificate
#!/bin/bash
# How To Create a client certificate
#As Root
cd /etc/ssl/myca
echo "Enter your username/tag!"
read USERNAME
echo "creating a CSR"
openssl req -config openssl.my.cnf -new -nodes -keyout private/${USERNAME}.key -out csr/${USERNAME}.csr -days 365
echo "Sign the CSR, get a Certificate"
@magiconair
magiconair / node-long-poll-1.js
Created February 1, 2011 15:27
Long polling server skeleton
/**
* Module import
*/
var express = require('express');
/**
* Port the server listens on
*/
var port = 3000;
# using rvm with ruby-1.8.7-p249
# latest version 2.7.7 2010-06-17
brew install libxml2
# installing libxslt from source code
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar xvfz libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.7
@peterc
peterc / mongodb
Created May 18, 2010 03:53
/opt/config/mongodb
# Configuration Options for MongoDB
#
# For More Information, Consider:
# - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters
# - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration
dbpath = /opt/mongo/data
logpath = /opt/mongo/logs/mongodb.log
logappend = true