Skip to content

Instantly share code, notes, and snippets.

View naveed-fida's full-sized avatar

Naveed Fida naveed-fida

  • Stack Builders
  • Peshawar, Pakistan
View GitHub Profile
@naveed-fida
naveed-fida / dom.js
Created January 25, 2017 06:51
Dom methods
// executes a callback for a dom element and all it's children
function walk(node, callback) {
callback(node);
node.childNodes.forEach(function(child) {
walk(child, callback);
});
}
// same functionality as the built-in one

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

@naveed-fida
naveed-fida / stringify.js
Last active November 21, 2016 14:36
An implementation of JSON.stringify
function stringifyObj(obj) {
let toStr = Object.prototype.toString;
if(toStr.call(obj) == "[object String]") {
return "\"" + String(obj) + "\"";
} else if (toStr.call(obj) == "[object Number]") {
return String(obj);
} else if(toStr.call(obj) == "[object Array]") {
let resultStr = "["
for (let i = 0; i < obj.length; i++) {
resultStr += stringifyObj(obj[i]);
@naveed-fida
naveed-fida / manual_http_request_handling.rb
Created July 11, 2016 14:35
Handling HTTP requests manually in ruby
require "socket"
def parse_request(request_line)
http_method, path_and_params, http_version = request_line.split(" ")
path, params = path_and_params.split("?")
params = (params || '').split("&").map {|p| p.split("=")}.to_h
[http_method, path, params]
end