Skip to content

Instantly share code, notes, and snippets.

View yushine's full-sized avatar

yushine yushine

View GitHub Profile
/**
* 百度统计订单跟踪
*
* 注意事项:
* 1. 页面需要安装百度统计的异步js代码,建议安装在页面顶部 </head> 标签之前,详情请参考获取代码页面的帮助信息。
* 2. 调用订单跟踪接口的位置,要在百度统计异步js代码的后面,至少要在 var _hmt = _hmt || []; 语句之后。
* 3. 所有字段名必须与示例中给出的名称保持字母和大小写完全一致。
*/
// 接口格式。
@yushine
yushine / where_is.rb
Last active August 29, 2015 14:25 — forked from wtaysom/where_is.rb
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
class ApplicationController < ActionController::Base
after_filter :store_referrer
protected
def store_referrer
return if referred_from_here? or request.format != 'text/html'
referrer_data = {
@yushine
yushine / facebook-wca-standard-events.html
Last active August 4, 2016 20:52 — forked from danielmcclure/facebook-wca-standard-events.html
Sample Facebook Standard Events for New Facebook WCA (Website Custom Audience) Pixel
<!-- Facebook Custom Audience Pixel Code - Placed on Every Page of Site -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','//connect.facebook.net/en_US/fbevents.js');
fbq('init', '{{facebook pixel}}');
fbq('track', 'PageView');
</script>
@yushine
yushine / Envoy.blade.php
Created September 1, 2016 10:26 — forked from gravitano/Envoy.blade.php
Envoy as Deployer
@servers(['web' => 'deploy-ex'])
@setup
$repo = 'git@github.com:Servers-for-Hackers/deploy-ex.git';
$release_dir = '/var/www/releases';
$app_dir = '/var/www/app';
$release = 'release_' . date('YmdHis');
@endsetup
@macro('deploy', ['on' => 'web'])
@yushine
yushine / polling.md
Created October 26, 2016 05:24 — forked from ksdev-pl/polling.md
Polling (setInterval, setTimeout) #js

The setInterval Technique

Now, if you needed to poll your web service, your first instinct might be to do something like this with JavaScript and jQuery:

setInterval(function(){
    $.ajax({ url: "server", success: function(data){
        //Update your dashboard gauge
        salesGauge.setValue(data.value);
 }, dataType: "json"});

pattern to replace setInterval with setTimeout

Register a task with setInterval and a interval is not desirable, since the task can take more time than the interval, so the compiler will skip through the current cycle. Replace setInterval with setTimeout with following pattern:

setInterval(function() {
    runSomething();
}, interval);

with

(function loop() {
@yushine
yushine / Envoy.blade.php
Created November 1, 2016 10:47
Laravel Envoy Task Runner
@servers(['staging' => 'root@192.168.0.99', 'production' => 'root@192.168.0.100'])
<?php
$app_name = 'l5eka';
$app_path = '/var/www/vhosts/'.$app_name;
$repo = 'https://github.com/vedovelli/l5eka';
$branch = 'aula4';
$github_token = ''; // GitHub OAuth token
$server_name = '192.168.0.99'; // IP ou domínio válido. Usado no nginx
<?php
class encrypt
{
private $key;
private $uword;
private $eword;
private $letters;
/**
@yushine
yushine / gist:f15d421833275607de5dbcf0025c1ead
Created January 23, 2017 07:15 — forked from pwlin/gist:1248250
php custom encrypt/decrypt
<?php
function encrypt($string, $key=5) {
$result = '';
for($i=0, $k= strlen($string); $i<$k; $i++) {
$char = substr($string, $i, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result .= $char;
}
return base64_encode($result);