Skip to content

Instantly share code, notes, and snippets.

View hlxwell's full-sized avatar
⛷️
Focusing

Michael He hlxwell

⛷️
Focusing
View GitHub Profile
@hlxwell
hlxwell / gist:f1e0084d1cb5517d86a5
Created June 15, 2014 09:25
Get Primebook book questions
Book.all.each do |book|
next if !book.pages.any? {|p| p.questions.count > 0}
puts "============ #{book.name} ==============="
book.pages.each do |page|
next if page.questions.count == 0
puts " Page##{page.page_number}"
page.questions.each do |question|
puts " * Question: #{question.content}"
question.question_options.each do |option|
puts " - #{option.content} #{"√" if option.is_correct_answer}"
#!/bin/sh
# Optware pre-installation script, Leon Kos 2006, 2008
# added -verbose_wget to some lines, MrAlvin 2009
REPOSITORY=http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/cross/stable
TMP=/tmp
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin
unset LD_PRELOAD
unset LD_LIBRARY_PATH
@hlxwell
hlxwell / render_to_file.rb
Last active December 20, 2015 20:59
How to render text in model
# One thing I don't know is how to pass @var to template.
def to_html
request = ActionDispatch::Request.new Hash.new
# I am using Gon also.
Gon.clear
Gon::Request.instance_variable_set(:@request_id, request.object_id)
Gon::Request.env = {}
# Assign gon variables
Gon.some_variables = self.some_variables

This was tested using Ruby 2.0.0 and Rails 4.0.0.rc1.

Bower

  1. Set the install directory for Bower components:

    // .bowerrc
    {

"directory": "app/assets/components"

@hlxwell
hlxwell / sign.sh
Created June 18, 2013 15:13
Sign mac app file
codesign -f -v -s "Mac Developer: lixing he (6EAVUH8752)" ./Sparkle.framework/Versions/A/Resources/relaunch
require "rubygems"
require "rspec"
class String
def syllable
# bl|qu|ng|ch|rt|
consonants = "bcdfghjklmnpqrstvwxzh"
vowels = "aeiouy"
word = self.downcase
parts = word.split(/(?=ly)/)
@hlxwell
hlxwell / sort_xcode_project.sh
Created May 21, 2013 03:48
Sort xcode project files, so could be helpful for the teamwork.
#!/usr/bin/perl -w
# Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
@hlxwell
hlxwell / new_gist_file
Created May 19, 2013 07:43
speex to google speech recognition
curl --data-binary @sound.spx --header 'Content-type: audio/x-speex-with-header-byte; rate=16000' 'https://www.google.com/speech-api/v1/recognize?client=chromium&lang=en-US&maxresults=2'
@hlxwell
hlxwell / new_gist_file
Created May 15, 2013 09:43
Get path for storing internet file to local
// Get a temp file path
[NSTemporaryDirectory() stringByAppendingPathComponent:@"myapptempdirectory.jpg"]);
// To get the filename from the url
[@"http://stackoverflow.com/questions/1098957/objective-c-extract-filename-from-path-string.jpg" lastPathComponent];
@hlxwell
hlxwell / new_gist_file
Created May 5, 2013 05:32
Replace placeholder in string
"%s %s" % ["a", "b"] => "a b"