Skip to content

Instantly share code, notes, and snippets.

View dqminh's full-sized avatar

Daniel, Dao Quang Minh dqminh

View GitHub Profile
package main
import (
"log"
"os"
"os/exec"
"time"
)
func main() {
#!/bin/bash
#replace /var/state and /var/state/mongodb with your proper path
sudo rm /var/state/mongodb/mongod.lock
sudo -u mongodb mongod --repair --dbpath=/var/state/mongodb
sudo /etc/rc.d/mongodb restart
@dqminh
dqminh / gist:964135
Created May 10, 2011 09:02
fetch_image.js
var janitor = new Image(),
info = {},
test = $("#test"),
images = [];
$.get("somewhere_that_fetch_the_page").complete(function (data) {
var tmpImages = $(data.responseText).find("img");
tmpImages.each(function (key, img) {
var src = (img.getAttribute ? img.getAttribute("src") : false) || img.src;
@dqminh
dqminh / jqtfilter.py
Created May 25, 2011 07:04
JS template filter for webassets
"""
Webasset filter to combine JQuery Templates files into javascript-safe strings,
and put them into a namespace
"""
import os
from webassets.filter import Filter
class JqtFilter(Filter):
name = 'jqt'
@dqminh
dqminh / gist:1029041
Created June 16, 2011 10:55
mongodb-restart
#!/bin/bash
mongo_path=/var/lib/mongodb
sudo rm $mongo_path/mongod.lock
sudo -u mongodb mongod --repair --dbpath=$mongo_path
sudo /etc/init.d/mongodb restart
@dqminh
dqminh / wordwrap.py
Created June 28, 2011 03:48
basic word wrap
def word_wrap(input, width):
input = input.strip()
if not input:
return ""
if len(input) < width:
return input
i = input.find(" ", width)
if i < 0:
return input[:width] + "\n" + word_wrap(input[width:], width)
#!/usr/bin/env ruby
def get_time(format="%H:%M")
Time.now.strftime("%H:%M")
end
case get_time
when "09:00"
`say you should finish your breakfast in 10 minutes`
when "11:55"
@dqminh
dqminh / christmas.tree
Created December 5, 2011 04:58
We want this tree
$
:$$
seeee$$$Neeee
R$$$F$$$$F
$$$$$$
@$$P*$$B
z$#" $#$b
" d 'N "
@" ?r
xF . "N
@dqminh
dqminh / applause_formatter.rb
Last active December 18, 2015 04:59
rspec formatter that applause you when your tests pass
require "rspec/core/formatters/progress_formatter"
class ApplauseFormatter < RSpec::Core::Formatters::ProgressFormatter
def initialize(output)
super(output)
unless File.exists? "/tmp/applause.mp3"
p "Downloading applause for awesomeness"
system "wget http://www.soundjay.com/human/applause-1.mp3 -O /tmp/applause.mp3"
end
end
pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d