Skip to content

Instantly share code, notes, and snippets.

View youtalk's full-sized avatar

Yutaka Kondo youtalk

View GitHub Profile
@youtalk
youtalk / GetFacebookLikesComments.js
Created June 21, 2012 14:06
Get the numbers of Facebook's likes and comments through Graph API
$.getJSON('https://graph.facebook.com/' + location.href, function (json) {
if (json) {
if (json.shares && json.shares > 0) {
$('a#fb-like > span > span.ui-btn-text')
.text($('a#fb-like').text().split(' ')[0] + ' ' + json.shares);
}
if (json.comments && json.comments > 0) {
$('a#fb-comment > span > span.ui-btn-text')
.text($('a#fb-comment').text().split(' ')[0] + ' ' + json.comments);
}
@youtalk
youtalk / i18n.translate.js
Created July 27, 2012 09:29
Yet another internationalization for Node.js
var translate = function (locale, singular, plural) {
if (locale === undefined) {
if (debug) logger.warn('i18n: no locale found');
locale = defaultLocale;
}
if (!locales[locale]) {
read(locale);
}
var capitalHead = new RegExp('^[A-Z]');
var upperHead = singular.match(capitalHead);
@youtalk
youtalk / redirect.http2https.js
Created July 31, 2012 12:42
Automatic redirection from HTTP to HTTPS with Node.js
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.configure('production', function () {
app.use (function (req, res, next) {
var schema = (req.headers['x-forwarded-proto'] || '').toLowerCase();
if (schema === 'https') {
@youtalk
youtalk / tinyxml.rb.diff
Last active August 29, 2015 14:01
diff tinyxml.rb /usr/local/Library/Formula/tinyxml.rb
diff --git a/Library/Formula/tinyxml.rb b/Library/Formula/tinyxml.rb
index da8a0d6..27a55eb 100644
--- a/Library/Formula/tinyxml.rb
+++ b/Library/Formula/tinyxml.rb
@@ -16,13 +16,13 @@ class Tinyxml < Formula
# The third patch adds a CMakeLists.txt file to build a shared library and provide an install target
# submitted upstream as https://sourceforge.net/p/tinyxml/patches/66/
patch do
- url "http://patch-tracker.debian.org/patch/series/dl/tinyxml/2.6.2-2/enforce-use-stl.patch"
+ url "https://raw.githubusercontent.com/robotology/yarp/master/extern/tinyxml/patches/enforce-use-stl.patch"
@youtalk
youtalk / Producer.cpp
Last active June 5, 2017 22:09
two_node_pipeline.cpp 1
// メッセージをPublishするPublisherクラス
struct Producer : public rclcpp::Node
{
Producer(const std::string & name, const std::string & output)
: Node(name, "", true)
{
// output名のトピックをPublishするPublisherを作成
pub_ = this->create_publisher<std_msgs::msg::Int32>(output, rmw_qos_profile_default);
// decltype(pub_.get())>はrclcpp::Publisher<std_msgs::msg::Int32>*
// std::remove_pointer<decltype(pub_.get())>はrclcpp::Publisher<std_msgs::msg::Int32>
@youtalk
youtalk / Consumer.cpp
Last active June 5, 2017 22:08
two_node_pipeline.cpp 2
// メッセージをSubscribeするSubscriberクラス
struct Consumer : public rclcpp::Node
{
Consumer(const std::string & name, const std::string & input)
: Node(name, "", true)
{
// input名のトピックをSubscribeするSubscriberを作成
sub_ = this->create_subscription<std_msgs::msg::Int32>(
input, [](std_msgs::msg::Int32::UniquePtr msg) { // std::unique_ptr<std_msgs::msg::Int32>の別名
printf(
@youtalk
youtalk / main.cpp
Last active June 5, 2017 22:11
two_node_pipeline.cpp
int main(int argc, char * argv[])
{
setvbuf(stdout, NULL, _IONBF, BUFSIZ);
rclcpp::init(argc, argv);
// 複数のノードを単一スレッドで実行させる実行器
rclcpp::executors::SingleThreadedExecutor executor;
auto producer = std::make_shared<Producer>("producer", "number");
auto consumer = std::make_shared<Consumer>("consumer", "number");
@youtalk
youtalk / constructor.cpp
Last active June 16, 2017 06:22
rclcpp::node::Node
explicit Node(
const std::string & node_name,
const std::string & namespace_ = "",
bool use_intra_process_comms = false);
@youtalk
youtalk / CallbackGroupType.cpp
Last active June 15, 2017 21:42
rclcpp::callback_group::CallbackGroupType
enum class CallbackGroupType
{
MutuallyExclusive,
Reentrant
};
@youtalk
youtalk / add_callback.cpp
Last active June 16, 2017 06:17
rclcpp::callback_group::CallbackGroup
void
add_subscription(const rclcpp::subscription::SubscriptionBase::SharedPtr subscription_ptr);
void
add_timer(const rclcpp::timer::TimerBase::SharedPtr timer_ptr);
void
add_service(const rclcpp::service::ServiceBase::SharedPtr service_ptr);
void