Skip to content

Instantly share code, notes, and snippets.

View meson10's full-sized avatar

Piyush Verma meson10

View GitHub Profile
@meson10
meson10 / future
Created October 14, 2014 09:39
future promise
function abc() {
var deferred = $.Deferred();
(function() {
var a = 1;
deferred.resolve(a);
})();
return deferred.promise();
}
@meson10
meson10 / types.go
Created December 14, 2014 15:12
types in go.
package main
import "fmt"
type myInt int
const unTypedC = 20
const typedC int = 30
func main() {
@meson10
meson10 / typecasting.go
Created December 14, 2014 15:13
typecasting in go
package main
import "log"
func alterValue(val interface{}) {
INCR := 10
switch i := val.(type) {
case nil:
log.Println("Nil value")
@meson10
meson10 / interfaces.go
Created December 14, 2014 15:14
Golang Interfaces
package main
import "log"
type EventLogger interface {
Log() int
}
type EventA struct {
Id int
@meson10
meson10 / concurrency.go
Created December 14, 2014 15:15
Concurrency in golang
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"sync"
)
@meson10
meson10 / race.go
Created April 4, 2015 03:10
Race Condition
package main
import (
"log"
"time"
)
type Inner struct {
Count int
}
@meson10
meson10 / panic_revcovery.go
Created July 18, 2015 20:00
If you observe, In case of panic recovery you can only prevent the function from crashing at exit.
package main
import "fmt"
func main() {
f()
fmt.Println("Returned normally from f.")
}
func f() {
@meson10
meson10 / hijack.rb
Created July 24, 2015 12:20
Hijack stdout and stderr for forks
require 'logger'
require 'stringio'
def capture_output
old_stderr, $stderr = $stderr, StringIO.new
old_stdout, $stdout = $stdout, StringIO.new
yield
[$stderr.string, $stdout.string]
ensure
$stderr = old_stderr
@meson10
meson10 / hijack_reopen.rb
Last active August 29, 2015 14:25
Hijacking that uses Reopening instead of Reassignment
require 'logger'
# require 'stringio'
# StringIO also do as IO, but IO#reopen fails.
# The problem is that a StringIO cannot exist in the O/S's file descriptor
# table. STDERR.reopen(...) at the low level does a dup() or dup2() to
# copy one file descriptor to another.
#
# I have two options:
@meson10
meson10 / plugin_function.go
Created August 30, 2015 08:56
Generic Plugin Function.
package main
import (
"fmt"
)
type BaseApp interface {
Name()
}