Skip to content

Instantly share code, notes, and snippets.

@ParthDesai
ParthDesai / generic_demo.go
Last active September 3, 2021 09:54
Generic map function in golang
package main
import (
"fmt"
"reflect"
)
func main() {
r := genericMap([]int{1, 2, 3, 4}, func(x int) string {
return "Hello"
@martinth
martinth / argparse_fileinput_demo.py
Created August 6, 2015 11:04
Read from stdin or files in Python (combining argparse and fileinput)
import argpase
import fileinput
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--dummy', help='dummy argument')
parser.add_argument('files', metavar='FILE', nargs='*', help='files to read, if empty, stdin is used')
args = parser.parse_args()
# If you would call fileinput.input() without files it would try to process all arguments.
@ebidel
ebidel / es6-meta-programming.js
Last active May 23, 2018 13:02
"ES6 meta programming" using tagged template strings
// ES6 meta programming ???
// The more complex form of ES6 template strings are called
// "tagged" template strings. In short, they allow you to
// pass the final evaluated string to a function for further
// processing. This allows for some interesting things. For example:
//
// get`https://api.github.com/repos/${org}/${repo}/issues?sort=${sort}`;
//
// _could_ make a network request and return a Promise with the result
@xDShot
xDShot / vk_ublock.txt
Last active June 3, 2019 19:50
uBlock filters to remove ads in vk.com. Just paste these lines into your filters.
vk.com##div[data-ad-view]
vk.com##div[data-ad]
vk.com##div[data-ads]
vk.com##.ads_ads_box
vk.com##.ads_ads_news_wrap
@skarllot
skarllot / enum.go
Created June 18, 2015 14:04
Enum-like types for Go (golang) that provides string representation
package main
import "fmt"
var enums []string
type Enum int
func (e Enum) String() string {
return enums[int(e)]
@hugooliveirad
hugooliveirad / readme.md
Created May 18, 2015 18:30
Diff two command outputs (stdout) without using files
type IntContainer []int
func (i IntContainer) Iterator(cancel <-chan struct{}) <-chan int {
ch := make(chan int)
go func() {
for _, val := range i {
select {
case ch <- val:
case <-cancel:
close(ch)
@nixzhu
nixzhu / cancelableDelayTask.swift
Last active March 11, 2017 17:10
Cancelable Delay Task
import Foundation
typealias CancelableTask = (cancel: Bool) -> Void
func delay(time: NSTimeInterval, work: dispatch_block_t) -> CancelableTask? {
var finalTask: CancelableTask?
var cancelableTask: CancelableTask = { cancel in
if cancel {