Skip to content

Instantly share code, notes, and snippets.

@yrong
yrong / pivot.js
Created August 31, 2019 13:25 — forked from parshap/pivot.js
Find pivot index
// Return the "pivot index" of the given array of numbers. The pivot index is
// the index where the sum of the numbers on the left is equal to the sum of
// the numbers on the right.
function pivot(numbers) {
validateInput(numbers);
// Find a pivot index by testing each index
for (var i = 0; i < numbers.length; i++) {
var leftSum = sum(numbers.slice(0, i));
var rightSum = sum(numbers.slice(i + 1));
@yrong
yrong / install_python.ps1
Created December 17, 2018 07:59 — forked from carlosfunk/install_python.ps1
Powershell scripts for setting up a Python environment under Windows
# To run this file you will need to open Powershell as administrator and first run:
# Set-ExecutionPolicy Unrestricted
# Then source this script by running:
# . .\install_python.ps1
$save_dir=Resolve-Path ~/Downloads
$project_dir = "C:\Projects"
$virtualenv_dir = $project_dir + "\virtualenvs"
$client = New-Object System.Net.WebClient
@yrong
yrong / nodejs_installer.ps1
Created November 26, 2018 09:21 — forked from nweldev/nodejs_installer.ps1
Powershell script installing nodejs (with git) and some npm packages
write-host "`n ## NODEJS INSTALLER ## `n"
### CONFIGURATION
# nodejs
$version = "4.4.7-x64"
$url = "https://nodejs.org/dist/latest-v4.x/node-v$version.msi"
# git
$git_version = "2.9.2"
@yrong
yrong / postgresql.py
Created July 30, 2018 01:06 — forked from robertsosinski/postgresql.py
DataDog script for collecting PostgreSQL stats
# Create the datadog user with select only permissions:
# CREATE USER datadog WITH PASSWORD '<complex_password>';
#
# Grant select permissions on a table or view that you want to monitor:
# GRANT SELECT ON <schema>.<table> TO datadog;
#
# Grant permissions for a specific column on a table or view that you want to monitor:
# GRANT SELECT (id, name) ON <schema>.<table> TO datadog;
#
# Let non-superusers look at pg_stat_activity in a read-only fashon.
@yrong
yrong / learn.lua
Created June 8, 2018 07:42 — forked from tylerneylon/learn.lua
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@yrong
yrong / crawler.go
Created May 30, 2018 11:11 — forked from avalanche123/crawler.go
A Tour of Go. Exercise: Web Crawler
package main
import (
"fmt"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
Fetch(url string) (body string, urls []string, err error)
@yrong
yrong / golang-nuts.go
Created March 15, 2018 01:38 — forked from ryanfitz/golang-nuts.go
two ways to call a function every 2 seconds
package main
import (
"fmt"
"time"
)
// Suggestions from golang-nuts
// http://play.golang.org/p/Ctg3_AQisl
@yrong
yrong / epoll.go
Created March 8, 2018 10:04 — forked from tevino/epoll.go
Golang example for using epoll
package main
import (
"fmt"
"net"
"os"
"syscall"
)
const (
var msgSend;
var counter = 0
setInterval(function(){
msgSend = new Buffer(counter.toString());
ipfs.pubsub.publish(topic, msgSend, (err) => {
if (err) {
throw err
}
// msg was broadcasted
})
@yrong
yrong / btree.hpp
Created February 24, 2018 07:41 — forked from zhenghaoz/btree.hpp
B Tree
#include <memory>
#include <vector>
#include <iostream>
template <unsigned N, typename Key, typename Value>
class BTree
{
template <typename T> using vector = std::vector<T>;
template <typename T> using shared_ptr = std::shared_ptr<T>;