Skip to content

Instantly share code, notes, and snippets.

View vanleantking's full-sized avatar
🤣

Le Van vanleantking

🤣
  • U
  • Binh Thanh
View GitHub Profile
@Cifro
Cifro / bookmark.html
Last active November 27, 2018 06:03
FB Friends Ranking
<a href="javascript:(function()%7Bfunction%20creator(e,t,n)%7Bvar%20r=document.createElement(n);var%20i=document.createTextNode(t);r.appendChild(i);e.appendChild(r)%7Dfunction%20displayData(e)%7Bvar%20t=document.createElement(%22table%22);var%20n=document.createElement(%22thead%22);t.appendChild(n);var%20r=document.createElement(%22tr%22);creator(r,%22Name%22,%22th%22);creator(r,%22Score%22,%22th%22);n.appendChild(r);var%20s=document.createElement(%22tbody%22);t.appendChild(s);for(i=0;i&lt;e.length;i++)%7Bvar%20r=document.createElement(%22tr%22);creator(r,e%5Bi%5D%5B%22text%22%5D,%22td%22);creator(r,e%5Bi%5D%5B%22grammar_costs%22%5D%5B%22%7Buser%7D%22%5D,%22td%22);s.appendChild(r)%7Ddocument.body.innerHTML=%22%22;document.body.appendChild(t)%7Did=requireDynamic(%22Env%22).user;url=%22//www.facebook.com/ajax/typeahead/search/facebar/bootstrap/?viewer=%22+id+%22&amp;__a=1%22;x=new%20XMLHttpRequest;x.onreadystatechange=function()%7Bif(x.readyState==4&amp;&amp;x.status==200)%7Bsrr=JSON.parse(x.responseText.substr
switch v.Kind() {
case reflect.Map:
// Map key must either have string kind, have an integer kind,
// or be an encoding.TextUnmarshaler.
t := v.Type()
switch t.Key().Kind() {
case reflect.String,
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
default:
@dz1984
dz1984 / utils.go
Created March 25, 2014 06:22
Utility Functions with Golang.
package utils
import (
"bufio"
"fmt"
"io/ioutil"
"os"
)
func IsExists(path string) bool {
@andykirk
andykirk / truncate_html.php
Last active October 8, 2019 10:00
PHP Truncate HTML Function
/**
* truncate_html()
*
* Truncates a HTML string to a given length of _visisble_ (content) characters.
* E.g.
* "This is some <b>bold</b> text" has a visible/content length of 22 characters,
* though the total string length is 29 characters.
* This function allows you to limit the visible/content length whilst preserving any HTML formatting.
*
* @param string $html
@teddyking
teddyking / waitgroup.go
Created August 23, 2016 10:34
Example of Go sync.WaitGroup
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var myWaitGroup sync.WaitGroup
package main
import (
"fmt"
"time"
)
type Topic struct {
message string
@lukecav
lukecav / functions.php
Created August 23, 2017 18:41
Reducing postmeta queries with update_meta_cache()
add_filter( 'posts_results', 'cache_meta_data', 9999, 2 );
function cache_meta_data( $posts, $object ) {
$posts_to_cache = array();
// this usually makes only sense when we have a bunch of posts
if ( empty( $posts ) || is_wp_error( $posts ) || is_single() || is_page() || count( $posts ) < 3 )
return $posts;
foreach( $posts as $post ) {
if ( isset( $post->ID ) && isset( $post->post_type ) ) {
$posts_to_cache[$post->ID] = 1;
@ardan-bkennedy
ardan-bkennedy / GoMgoSample-1.go
Last active February 27, 2021 08:31
Sample Go and MGO example
type (
// BuoyCondition contains information for an individual station.
BuoyCondition struct {
WindSpeed float64 `bson:"wind_speed_milehour"`
WindDirection int `bson:"wind_direction_degnorth"`
WindGust float64 `bson:"gust_wind_speed_milehour"`
}
// BuoyLocation contains the buoy's location.
BuoyLocation struct {
@jwickett
jwickett / Multi-Threaded_Web_Crawler.py
Created December 22, 2009 06:32
A multi-threaded Web crawler implemented in Python
import threading, urllib, urlparse
from HTMLParser import HTMLParser
import sys
class LinkHTMLParser(HTMLParser):
A_TAG = "a"
HREF_ATTRIBUTE = "href"
def __init__(self):
self.links = []
@CristhianBoujon
CristhianBoujon / get_top_n_words.py
Last active May 20, 2021 09:14
List the words in a vocabulary according to occurrence in a text corpus , Scikit-Learn
def get_top_n_words(corpus, n=None):
"""
List the top n words in a vocabulary according to occurrence in a text corpus.
get_top_n_words(["I love Python", "Python is a language programming", "Hello world", "I love the world"]) ->
[('python', 2),
('world', 2),
('love', 2),
('hello', 1),
('is', 1),