Skip to content

Instantly share code, notes, and snippets.

𝚊𝚋𝚜𝚝𝚛𝚊𝚌𝚝𝚒𝚘𝚗 & 𝚌𝚘𝚖𝚙𝚕𝚎𝚡𝚒𝚝𝚢

Draven draveness

𝚊𝚋𝚜𝚝𝚛𝚊𝚌𝚝𝚒𝚘𝚗 & 𝚌𝚘𝚖𝚙𝚕𝚎𝚡𝚒𝚝𝚢
View GitHub Profile
draveness / 0_reuse_code.js
Created Jan 14, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
draveness / fishhook-test-viewcontroller
Last active Sep 1, 2016
Using fishhook to change socket layer function and failed because of recursive call
View fishhook-test-viewcontroller
#import "ViewController.h"
#import <fishhook.h>
@interface ViewController () <NSURLSessionDataDelegate>
@implementation ViewController
int (*origianl_connect)(int, const struct sockaddr *, socklen_t);
View disqus-migrator.rb
require 'csv'
require 'uri'
require 'pry'
csv_text ='1.csv')
csv = CSV.parse(csv_text, :headers => true)
hashes = []
csv.each do |row|
hash = row.to_hash
old = hash["old"]
View old-style-plist-parser.swift
// Token.swift
// XProject
// Created by Draveness on 05/04/2017.
// Copyright © 2017 Draveness. All rights reserved.
import Foundation
import RbSwift

Keybase proof

I hereby claim:

  • I am Draveness on github.
  • I am draven ( on keybase.
  • I have a public key whose fingerprint is 62CA 63CD FC29 5526 5B5E 9141 30B1 E305 0480 F92E

To claim this, I am signing this object:

View embeds_many_to_has_many.rb
def embeds_many_to_has_many(parent, child)
child_key_name = child.to_s.underscore.pluralize
parent.collection.find({}).each do |parent_document|
next unless parent_document[child_key_name]
parent_document[child_key_name].each do |child_document|
new_child = child_document.merge(
"#{parent.to_s.underscore}_id": parent_document['_id']
child.collection.insert_one new_child
draveness / monitor_database_record_creation.rb
Last active Sep 29, 2017
Monitor FactoryGirl record creation with ActiveSupport notifications
View monitor_database_record_creation.rb
# source:
# spec/spec_helper.rb
config.before(:each, :monitor_database_record_creation) do |example|
ActiveSupport::Notifications.subscribe("factory_girl.run_factory") do |name, start, finish, id, payload|
$stderr.puts "FactoryGirl: #{payload[:strategy]}(:#{payload[:name]})"
draveness / database_transformer.rb
Last active Sep 29, 2017
Export MongoDB to csv files and import them into MySQL with mysqldump
View database_transformer.rb
module DatabaseTransformer
def self.import(collection, fields, columns)
mongo_export = <<-EOF
mongoexport --host #{hostname} --username #{username} \
--password #{password} \
--authenticationDatabase #{auth_source} \
--db #{database} --collection #{collection} \
--type=csv \
--fields #{fields.join(',')} \
--out #{collection}.csv
draveness / database_transformer.rb
Last active Oct 7, 2017
Export MongoDB collection to ActiveRecord Model directly. Used for MongoId to ActiveRecord migration.
View database_transformer.rb
# frozen_string_literal: true
require 'colorize'
module DatabaseTransformer
attr_reader :database
def initialize(database)
@database = database
draveness / relation_builder.rb
Last active Oct 7, 2017
After export all the record from MongoDB, use this to build relation in all records. You need to handle many to many relations by yourself
View relation_builder.rb
# frozen_string_literal: true
require 'colorize'
module RelationBuilder
attr_reader :constants
def initialize(constants = [])
if constants.present?
@constants = constants