Skip to content

Instantly share code, notes, and snippets.

@element6
element6 / 0_reuse_code.js
Created October 14, 2015 06:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@element6
element6 / gist:a98122b888a5707c5cb3
Created October 14, 2015 06:12
put query string into jquery object
$.QueryString = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i) {
var p = a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
@element6
element6 / gist:f5f4627a137dd16dbf79
Created October 14, 2015 06:16
get or restore form values
//$('form').values() or $('form').values(v)
$.fn.values = function(data) {
var els = $(this).find(':input').get();
if (typeof data != 'object') {
// return all data
data = {};
$.each(els, function() {
if (this.name && !this.disabled && (this.checked
@element6
element6 / gist:a70ddba5d73465b4fb92
Created October 27, 2015 00:14
fix permission issue with npm install
sudo chown -R $USER /usr/local
md5check(){
MSG=$(md5 $1 | grep -e "= $2$")
if [ -z "$MSG" ]; then
echo "Failed"
else
echo $MSG "Match"
fi
}
usage: md5check <filename> <md5sum to match>
@element6
element6 / gist:6de6a89296f4f495afa6
Last active November 13, 2015 03:22
javascript pub/sub event helper
var events = (function() {
var topics = {};
return {
sub: function(topic, listener) {
topics[topic] = topics[topic] || [];
var index = topics[topic].push(listener) - 1;
// Provide handle back for removal of topic
@element6
element6 / gist:dd79ec86e90df7d3bdf9
Created January 5, 2016 03:51
pdf to png on mac
sips -s format png your_pdf_file.pdf --out your_png_file.png
@element6
element6 / gist:cd0803300f5539fea39653956ce4a7dd
Created June 27, 2016 03:13
search the first occurrence of some text in git repo
git log -S "some text" --source --all
@element6
element6 / binary.py
Last active May 19, 2017 04:19
binary search
#http://code.activestate.com/recipes/81188-binary-search/
def binary_search(seq, t):
min = 0
max = len(seq) - 1
while True:
if max < min:
return -1
m = min + (max - min) // 2
if seq[m] < t:
min = m + 1
@element6
element6 / gist:de2e78a1a700feabf8e016f4fb14748b
Created May 21, 2017 10:26
less with color and line number
less -RN <filename>