Skip to content

Instantly share code, notes, and snippets.

View JokerCatz's full-sized avatar

JokerCatz JokerCatz

View GitHub Profile
@JokerCatz
JokerCatz / quilt.rb
Created February 24, 2016 16:53
lib_quilt
# -*- coding: utf-8 -*-
##source from https://github.com/swdyh/quilt
require 'digest/sha1'
module Quilt
SALT = ''
PATCHES = [[0,4,24,20,0],[0,4,20,0],[2,24,20,2],[0,2,22,20,0],[2,14,22,10,2],[0,14,24,22,0],[2,24,22,13,11,22,20,2],[0,14,22,0],[6,8,18,16,6],[4,20,10,12,2,4],[0,2,12,10,0],[10,14,22,10],[20,12,24,20],[10,2,12,10],[0,2,10,0],[]]
CENTER_PATCHES = [0,4,8,15]
PATCH_SIZE = 5
@JokerCatz
JokerCatz / adwords_keyword_planner_demo_code
Created March 31, 2016 11:22
adwords keyword planner demo code
require 'adwords_api'
def get_keyword_ideas(keyword_text)
adwords = AdwordsApi::Api.new
targeting_idea_srv = adwords.service(:TargetingIdeaService, API_VERSION)
selector = {
:idea_type => 'KEYWORD',
:request_type => 'IDEAS',
:requested_attribute_types =>
['KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES' , 'AVERAGE_CPC'],
@JokerCatz
JokerCatz / i18n_unused_scanner.rb
Created April 1, 2016 04:29
Rails i18n unused key scanner
require 'yaml'
require 'awesome_print'
require 'open3'
###### keys diff start
def flat_hash(hash , flag = [] , global = {})
return global.update({flag=>hash}) unless hash.is_a?(Hash)
hash.each do |key,rnd|
flat_hash(rnd,flag+[key],global)
@JokerCatz
JokerCatz / ruby_aop.rb
Last active October 20, 2018 06:09
Ruby lightweight AOP
# AOP = Aspect-Oriented Programming
module AOP
class Error < StandardError
attr_accessor :flag
attr_accessor :origin_flag
attr_accessor :origin # store raw exception
end
@JokerCatz
JokerCatz / led.cpp
Created December 1, 2018 05:06
rpi-rgb-led-matrix unix socket server
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdlib.h>
#include <pthread.h>
@JokerCatz
JokerCatz / gif.go
Created December 1, 2018 05:10
rpi-rgb-led-matrix unix socket client by Golang (animation gif reader)
package main
import (
"bufio"
"flag"
"fmt"
"image"
"image/draw"
"image/gif"
"log"
# License : WTF License
# for Rails project & put it at %RAILS_APP%/script/i18n_unused_scanner.rb and exec it
# just for fun , only test with OSX
require 'yaml'
require 'open3'
require 'awesome_print'
module I18nUnusedScanner
SEARCH_PATTERNS = %w(js rb erb html)
@JokerCatz
JokerCatz / session_store.rb
Created January 17, 2020 03:10
Rails6 Redis Session Store (serializer by JSON)
# -*- encoding : utf-8 -*-
Rails.application.config.session_store(
:redis_store,
key: "_#{Rails.application.class.parent_name.downcase}_session",
expire_after: 2.days,
threadsafe: true,
url: "redis://127.0.0.1:6379/8",
)
# Redis session store(serializer by JSON) for Rails 6
@JokerCatz
JokerCatz / session_share.go
Created April 2, 2020 17:55
Golang get Rails redis session & verify auth token
package main
import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"regexp"
"strconv"
@JokerCatz
JokerCatz / vlc_converter_main.go
Last active February 4, 2021 10:06
golang , vlc , mp4 to mp3 , test at macOS , and not stable
package main
import (
"bytes"
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"