Skip to content

Instantly share code, notes, and snippets.

@maruware
maruware / og.php
Created August 28, 2015 04:04
og locales
<?php
$locale_tags = [
'en_US'=>[
'title'=>'hello',
'description'=>'hello world'
],
'fr_FR'=>[
'title'=>'Bonjour',
'description'=>'Bonjour tout le monde'
],
@maruware
maruware / TemplateUtil.php
Created July 14, 2015 12:27
Evaluate Template
<?php
class TemplateUtil{
public static function evalTemplate($template_file, $vars)
{
ob_start();
foreach($vars as $key=>$val){
${$key} = $val;
}
@maruware
maruware / not_finish.py
Created October 30, 2015 05:23
Enigma on GridSearchCV & requests
# -*- coding: utf-8 -*-
from sklearn.grid_search import GridSearchCV
from sklearn.linear_model import LogisticRegression
import requests
import numpy as np
import random
sample_num = 1400
dimension = 100
@maruware
maruware / fetch_rate_limit_status.rb
Created November 25, 2015 03:44
fetch "rate_limit_status" with twitter gem
client = Twitter::REST::Client.new do |config|
config.consumer_key = "..."
config.consumer_secret = "..."
end
res = Twitter::REST::Request.new(client, :get, '/1.1/application/rate_limit_status.json').perform
#ex.
p res[:resources][:search][:'/search/tweets'][:remaining]
@maruware
maruware / unicorn.rb
Created March 17, 2016 02:47
config/unicorn.rb
rails_root = File.expand_path('../../', __FILE__)
listen "#{rails_root}/tmp/sockets/unicorn.sock"
pid "#{rails_root}/tmp/pids/unicorn.pid"
stdout_path "#{rails_root}/log/#{:stage}.log"
stderr_path "#{rails_root}/log/#{:stage}.log"
timeout 60
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 2)
@maruware
maruware / install-ffmpeg-amazon-linux.sh
Last active April 25, 2016 12:53 — forked from gboudreau/install-ffmpeg-amazon-linux.sh
How to compile ffmpeg on Amazon Linux (EC2)
#!/bin/sh
# Based on instructions found here: http://wiki.razuna.com/display/ecp/FFMpeg+Installation+on+CentOS+and+RedHat#FFMpegInstallationonCentOSandRedHat-InstallX264
if [ "`/usr/bin/whoami`" != "root" ]; then
echo "You need to execute this script as root."
exit 1
fi
cat > /etc/yum.repos.d/centos.repo<<EOF
@maruware
maruware / FileInput.js
Created April 19, 2017 06:41
File upload on admin-on-rest
import React from 'react';
import { Field } from 'redux-form';
const FileInput = (props) => (
<span>
<Field name={props.name} component="input" type="file" label={props.label} />
</span>
);
export default FileInput;
@maruware
maruware / SpeedDial.jsx
Created February 7, 2018 03:54
Material-UI SpeedDial Example
import React, {Component} from 'react'
import classNames from 'classnames'
import Button from 'material-ui/Button'
import Tooltip from 'material-ui/Tooltip'
import { withStyles } from 'material-ui/styles'
const actionMargin = 20
const actionSize = 40
@maruware
maruware / cors.js
Created April 27, 2018 03:11
Attach cors header on AWS Lambda (nodejs8.10)
module.exports = (response) => {
const {headers, ...rest} = response
return {
...rest,
headers: {
'Access-Control-Allow-Origin': '*',
...headers
}
}
}
@maruware
maruware / provision.sh
Created August 13, 2018 10:46
Setup SSH with MFA
sudo apt-get update
sudo apt-get install -y libpam-google-authenticator
ga_profile=$(cat << EOS
#!/bin/sh
if [ "$USER" != "root" ]; then
if [ ! -f "$HOME/.google_authenticator" ]; then
trap 'exit' SIGINT
echo "Initialize google-authenticator"