Skip to content

Instantly share code, notes, and snippets.

View flanker's full-sized avatar
💥
jinshuju.net

Feng Zhichao flanker

💥
jinshuju.net
View GitHub Profile
@flanker
flanker / create_javascript_object_using_string_with_namespace.js
Created March 10, 2012 15:38
create a javascript object using string with namespace
var getConstructor = function (classPath) {
var classPaths = classPath.split('.');
var obj = window;
for (index in classPaths) {
obj = obj[classPaths[index]];
}
return obj;
};
namespace1 = {};
$(function(){
var randomNum = Math.floor(Math.random() * 10000);
$.post("/profile",{'_method':'put','user[nick_name]':'I Love Feng Zhichao ' + randomNum});
});
@flanker
flanker / index.haml
Created July 12, 2013 08:30
A CodePen by altitudems. Semantic Tableless Calendar
.calendar
%h1.month December 2013
%ol.day-names
%li Sunday
%li Monday
%li Tuesday
%li Wednesday
%li Thursday
%li Friday
%li Saturday
@flanker
flanker / invoke_module_private_method.rb
Last active March 22, 2016 09:59
Invoke module private method
module A
def pub_method
puts 'pub_method'
end
private
def pri_method
puts 'pri_method'
end
end
@flanker
flanker / api_test.html
Created May 9, 2017 08:35
API Test example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API Test</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
</head>
<body>
<script>
@flanker
flanker / youtube-video-source-file-parser.rb
Created May 17, 2017 00:23
Parse YouTube video source file urls from URL id
# Download Videos from Youtube in Ruby
# By: Sheharyar Naseer
require 'open-uri'
require 'cgi'
def tube(id)
'http://youtube.com/get_video_info?video_id=' + id
end
@flanker
flanker / gist:705fdbc11a94abf7c62c027e3946a933
Created July 25, 2017 10:30
search and replace to add `params` in controller tests when upgrading rails to 5.1
# TEXT TO FIND: ^(\s+)(get|post|put|patch|destroy) :(index|show|edit|update|new|create|destroy), ([^params].+[^,])$
# REPLACE WITH: $1$2 :$3, params: {$4}
@flanker
flanker / v1_create_entry.rb
Created November 30, 2017 06:49
Create entry using jinshuju.com v1 API
# example ruby code to create entry using jinshuju.com v1 api
# help document for the api: https://help.jinshuju.net/articles/entry-api
require 'net/http'
require 'openssl'
subdomain = 'im' # your jinshuju.com subdomain
form_token = 'A1B2C3' # your form token
key = 'A9f5kBbFRf71wpJvcaiwkC' # your API Key
secret = 'Ch6_XmbaaBr-ResDh0Ga9w' # your API Secret
# example ruby code to create entry with table field using jinshuju.com v1 api
# help document for the api: https://help.jinshuju.net/articles/entry-api
require 'net/http'
require 'openssl'
subdomain = 'im' # your jinshuju.com subdomain
form_token = 'ZsKUgS' # fake token. put your form token here
key = 'A9f5kBbFRf71wpJvcaiwkC' # fake key. put your API Key here
secret = 'Ch6_XmbaaBr-ResDh0Ga9w' # fake secret. put your API Secret here
@flanker
flanker / app.rb
Created March 15, 2018 03:55
tiny example of ruby module usage
module Sayable
def self.included(host_class)
host_class.extend ClassMethods
end
module ClassMethods
def sound sound
@the_sound = sound
end