Skip to content

Instantly share code, notes, and snippets.

@kazu69
kazu69 / Rakefile
Last active August 29, 2015 14:04
Rails4.1.4 create rails plugin width rspec
# Rakefile
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'rdoc/task'
fn current_branch(path: &Path) -> String {
let head_ref = head_ref(path);
println!("The ref for HEAD is {}", head_ref);
let r = regex!(r"refs/heads/(.+)");
let caps_result = r.captures(head_ref.as_slice());
let branch: String = match caps_result {
Some(cap) => { String::from_str(cap.at(1)) },
None => { panic!("You must be somewhere on refs/heads, and you aren't") }
};
branch
@archer884
archer884 / parallel_prime_spike.rs
Last active August 29, 2015 14:12
Parallel prime finding nonsense
use std::iter::iterate;
use std::num::Float;
use std::sync::Future;
fn main() {
if let Some(n) = read_uint(1) {
let sum_of_primes = {
let block_size = if n > 999 { n / 20 } else { n };
let mut futures = Vec::new();
@brixen
brixen / gist:2dbabdff1c70cc3856b5
Created June 27, 2015 18:55
Method call histogram by inline cache type
Inline cache type: Rubinius::MonoInlineCache
Hits Module Name
563069 Fixnum +
401513 Rubinius::Tuple at
391974 Fixnum <
214380 Array each
187879 Fixnum ==
132183 Array []
127737 Fixnum -
126048 Fixnum >
@mrdanadams
mrdanadams / controller.rb
Created March 28, 2012 20:55
Boosting search results for Facebook friends with fb_graph, omniauth, Sunspot and Solr
ids = current_user.facebook_friends if current_user
@search = Profile.solr_search do
keywords params[:q] do
boost_fields name: 10.0, user: 4.0
end
unless ids.blank?
adjust_solr_params do |params|
# See "bq (boost query)" in http://wiki.apache.org/solr/DisMaxQParserPlugin
params[:bq] = "facebook_id_s:(#{ids.join(' OR ')})^10"
有人用过cell么?
<span style="font-size: small;"><a target="_blank" href="http://rubyforge.org/frs/?group_id=2978&amp;release_id=9650">http://rubyforge.org/frs/?group_id=2978&amp;release_id=9650</a>
<br /></span>
<br /><span style="font-size: small;"> </span>
<br /><span style="font-size: small;">
<br />非常小,源代码一目了然。感觉虽然有点土,但比自己做个module的方式好一点点
<br />号称: 代替发挥component作用的controller, 这样就不需要邪恶的render_component了
<br /></span>
<br /><span style="font-size: small;">A cell acts as a lightweight controller in the sense that it will assign variables and render a view.</span>
@robertlyc
robertlyc / remove osx menu duplicate item
Created August 29, 2012 07:10
删除osx菜单多余选项
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system-domainuser
@mrichie
mrichie / gist:4367339
Last active December 10, 2015 02:28
server app
if [ "$(id -u)" -eq "0" ]; then
echo "This script should not be run as root"
exit 1
fi
sudo ntpdate ntp.ubuntu.com
sudo apt-get install gcc -y
sudo apt-get install language-pack-zh-hant language-pack-zh-hans -y
sudo apt-get install yasm imagemagick ghostscript libsasl2-dev libmemcached-dev -y
@JEG2
JEG2 / struct.md
Created June 3, 2013 21:50
Thinking out loud about the merits and drawbacks of two different usages of Struct…

How Should We Use Struct?

The Choice

It's common in Ruby to see some code setup a Struct like this:

class Specialized < Struct.new(:whatever)
  # ... define custom methods here...
end
@preshing
preshing / list_modifications.py
Last active January 21, 2016 04:44
List the contents of folders recursively, sorted by modification time.
#! /usr/bin/env python
# License: http://creativecommons.org/publicdomain/zero/1.0/
# See http://preshing.com/20130115/view-your-filesystem-history-using-python
import optparse
import os
import fnmatch
import time
# Parse options
parser = optparse.OptionParser(usage='Usage: %prog [options] path [path2 ...]')