Skip to content

Instantly share code, notes, and snippets.

// Implement generic for two way linked list for different items type.
interface ILinkedList<T> {
append(value: T);
pop():T|null;
showlist():void;
}
class LinkedList<T> implements ILinkedList<T> {
public head:MyNode<T>
@DmytroVasin
DmytroVasin / hash_size.rb
Last active June 17, 2018 11:58
Time to add a new key/value pair (ms)
# Ruby -v: 2.3.4
# Chart: https://jsfiddle.net/81ef590x/116/
require 'benchmark'
def without_gc
GC.start
GC.disable
yield
GC.enable
@DmytroVasin
DmytroVasin / GC Pulse on JS
Last active April 5, 2018 05:37
Pulse of Garbage Collector in V8. See more: https://www.youtube.com/watch?v=ZAJmJmKWNPw
getFakeHistory = function(){
return (new Array(20000).join('a'))
}
function Record(id, description) {
this.id = id;
this.description = description;
}
# We need that function to prevent V8 optimisation
@DmytroVasin
DmytroVasin / PouchDB
Created March 11, 2018 16:46
PouchDB
https://github.com/gtaranas/forecaster/blob/47707dcbfd7c23acedbd7428ae35a8696aaa8c49/src/renderer/datastore.js
https://codepen.io/lonekorean/pen/xGLLwX?editors=1100
import PouchDB from 'pouchdb-browser'
import path from 'path'
import { remote } from 'electron'
const db = new PouchDB(path.join(remote.app.getPath('userData'), '/data.db'))
@DmytroVasin
DmytroVasin / redux.rb
Created February 4, 2018 12:14
Ruby implementation of redux store
todos_reducer = -> (state, action) {
state ||= []
case action[:type]
when 'add'
state.push(action[:todo])
when 'remove'
state.remove(action[:todo])
else
state
require 'faraday'
require 'pluck_all'
require 'eventmachine'
require 'em-http-request'
require 'pry'
EventMachine.run {
total_size = 0
p 'start'
@DmytroVasin
DmytroVasin / EM+Callback
Created December 23, 2017 21:25
EM+Callback
require 'pluck_all'
require 'eventmachine'
require 'em-http-request'
# require 'pry'
# EventMachine.run do
# page = EventMachine::HttpRequest.new('http://google.ca/').get
# page.errback { p "Google is down! terminate?" }
# page.callback {
# about = EventMachine::HttpRequest.new('http://google.ca/search?q=eventmachine').get
@DmytroVasin
DmytroVasin / Thread_Mutext.rb
Last active December 23, 2017 21:22
Threads + Mutext
desc 'Video thumbnails'
task video_thumbnails_ping: :environment do
p 'video_thumbnails_ping START'
t1 = Time.now
THREAD_COUNT = 8 # tweak this number for maximum performance.
MAX_COUNT = 5000
thumbnails = Thumbnail.last(MAX_COUNT).pluck(:id, :combined_url_2, :combined_url_1)
@DmytroVasin
DmytroVasin / routes#devise.rb
Last active October 25, 2017 15:05
Splited file
Rails.application.routes.draw do
ActiveAdmin.routes(self)
devise_for :users, skip: [:sessions, :registrations, :passwords, :confirmations]
devise_scope :user do
# Sessions:
post 'auth/sign_in', to: 'auth/sessions#create', as: :user_session, defaults: { format: 'js' }
get 'auth/sign_out', to: 'auth/sessions#destroy', as: :destroy_user_session, defaults: { format: 'html' }
# Registrations:
post 'auth', to: 'auth/registrations#create', as: :user_registration, defaults: { format: 'js' }
@DmytroVasin
DmytroVasin / application.rb
Created October 25, 2017 14:47
routes joiner
config.paths['config/routes.rb'] = Dir[Rails.root.join('config/routes/*.rb')]