Skip to content

Instantly share code, notes, and snippets.

View ndkhoa's full-sized avatar

Nguyen Dang Khoa ndkhoa

View GitHub Profile
@ndkhoa
ndkhoa / agnoster-newline.zsh-theme
Created October 31, 2018 09:21 — forked from nweddle/agnoster-newline.zsh-theme
Agnoster ZSH Theme with New Line
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
@ndkhoa
ndkhoa / noti.sh
Created December 7, 2018 06:55 — forked from John-Almardeny/noti.sh
Create a Notification With Sound with a Given Message and Time in Linux-Like OS
#!/bin/sh
# https://gist.github.com/John-Almardeny/04fb95eeb969aa46f031457c7815b07d
# Create a Notification With Sound with a Given Message and Time
# The Downloaded Sound is from Notification Sounds https://notificationsounds.com/
MSSG="$1"
TIME="$2"
# install wget if not found
@ndkhoa
ndkhoa / reoder.js
Last active January 18, 2019 09:43
Re-oder element
javascript:(function()%7Bfunction callback()%7B(function(%24)%7Bvar jQuery%3D%24%3B%24.fn.swap %3D function (elem) %7Belem %3D elem.jquery %3F elem %3A %24(elem)%3Breturn this.each(function () %7B%24(document.createTextNode('')).insertBefore(this).before(elem.before(this)).remove()%3B%7D)%3B%7D%3Bfunction getPrice(e)%7Breturn Number(%24(%24(e).find('.product-item__price--final')%5B0%5D).text().match(%2F%5B0-9%5D%2Fg).join(''))%3B%7Dfunction sortProducts()%7Bproducts %3D %24('.product-item.product-item-flashdeal')%3Bfor (i %3D 0%3B i < products.length - 1%3B i%2B%2B) %7Bvar k %3D i%3Bfor (j %3D i %2B 1%3B j < products.length%3B j%2B%2B) %7Bproducts %3D %24('.product-item.product-item-flashdeal')%3Bp2 %3D %24(products%5Bj%5D)%3Bp1 %3D %24(products%5Bi%5D)%3Bif(getPrice(p1) > getPrice(p2))%7Bk %3D j%3Bp1.swap(p2)%3B%7D%7D%7D%7DloadingTime %3D 1%3BlastHeight %3D 0%3BloadingMorePage %3DsetInterval(function()%7Bif(lastHeight < %24(document).height())%7Bconsole.log("Scrolling to bottom%3A " %2B loadingTime %2B " tim
@ndkhoa
ndkhoa / main.go
Created February 25, 2019 17:39
binary search
package main
import "fmt"
func BinarySearch(array []int, element int) int {
low := 0
high := len(array) - 1
for low <= high {
index := (high + low) / 2
@ndkhoa
ndkhoa / note.txt
Created February 26, 2019 11:20
Sorting Algorithms
https://medium.com/@limichelle21/read-it-learn-it-build-it-sorting-algorithms-in-ruby-ead04b04baa6
https://en.wikipedia.org/wiki/Sorting_algorithm#Stability
https://www.rubyguides.com/2017/07/ruby-sort/
https://8thlight.com/blog/will-warner/2013/03/26/stable-sorting-in-ruby.html
https://nguyenvanhieu.vn/thuat-toan-tim-kiem-nhi-phan/
https://nguyenvanhieu.vn/thuat-toan-sap-xep-bubble-sort/
@ndkhoa
ndkhoa / main.go
Created February 27, 2019 02:16
Bubble Sort
package main
import "fmt"
func BubbleSort(array []int) []int {
endIndex := len(array)
var flag, counter int
// Cach 1
// counter = 0
@ndkhoa
ndkhoa / main.go
Created February 27, 2019 02:17
Insertion Sort
package main
import "fmt"
func InsertionSort(array []int) []int {
var counter int
size := len(array)
for i := 1; i < size; i++ {
for j := i; j > 0 && array[j-1] > array[j]; j-- {
counter++
@ndkhoa
ndkhoa / main.c
Last active March 5, 2019 15:21
Finding the first duplicate character in the string Ruby
#include <stdio.h>
int main(){
int arr[127]={0};
char *str="a1221321bbccasdcsd";
int length=(int)sizeof(str)/sizeof(str[0]);
int i;
for(i=0;i<length;i++)
{
arr[*(str+i)]+=1;
@ndkhoa
ndkhoa / main.rb
Created March 5, 2019 11:40
Ruby: work with block
class Array
def go_map
raise unless block_given?
result = []
each { |element| result << yield(element) }
result
end
end
[1, 2, 3].go_map
@ndkhoa
ndkhoa / main.rb
Last active March 11, 2019 03:07
Fibonacci
def fibonacci(number)
return number if (0..1).cover?(number)
fibonacci(number - 1) + fibonacci(number - 2)
end
def fibonacci_array(number)
return 'nil' if number < 1
array = []