Skip to content

Instantly share code, notes, and snippets.

@BayPhillips
BayPhillips / dumbuiviewcontroller
Last active June 8, 2017 13:17
A dumb Swift UIViewController with UITableView
import UIKit
class DumbViewController: UIViewController, UITableViewDataSource {
var items: [Int] = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.whiteColor()
@axgle
axgle / undo.php
Last active August 29, 2015 14:01
<?php
class db{
static $count=0;//current data
static $undos=array();//stack
}
function add($n){
db::$count+=$n;
db::$undos[]=function() use($n){
db::$count-=$n;
@axgle
axgle / sync.Pool.md
Last active December 18, 2022 09:56

What is sync.Pool in golang and How to use it

sync.Pool (1/2)

Many Go libraries include custom thread-safe free lists, like this:

var objPool = make(chan *Object, 10)

func obj() *Object {

select {

@deckarep
deckarep / goroutine-channel-pattern.go
Last active December 13, 2016 20:46
A Goroutine safe pattern using channels that abstracts away the usage of channels.
/*
A Goroutine safe pattern using channels that abstracts away the channels
This is a concept of creating a goroutine safe object that uses channels under the covers to communicate
with the internal map[string]string structure. I know that typically this kind of solution may done
with mutexes but the excercise was in using channels on purpose although they are heavier.
Note a couple of points:
- When using channels, you can still build a public-facing api that nicely abstracts them away, therefore
@gmodarelli
gmodarelli / Multiple PHP under Ubuntu 13.04.md
Last active July 6, 2021 05:23
How to setup Ubuntu 13.04 to work with multiple PHP version at the same time

Multiple PHP version under Ubuntu 13.04

Update your machine

apt-get update
apt-get ugrade

Install some dependencies

apt-get install build-essential

@smagch
smagch / CondSpike.go
Last active December 15, 2015 02:18
sync.Cond test
package main
import (
"log"
"time"
"sync"
)
const NUM = 2
var finished = make(chan bool, NUM)
@scribu
scribu / test.php
Created February 8, 2013 03:12
Simulate threads in PHP using only proc_open() and co.
<?php
include __DIR__ . '/threads.php';
$commands = array();
for ( $i=0; $i<10; $i++ ) {
$commands[] = "bash -c 'sleep `shuf -i 1-5 -n 1`; echo $i'";
}
@hnaohiro
hnaohiro / go-unzip
Created January 19, 2013 13:01
Golangでzipファイルを解凍するサンプル
package main
import (
"archive/zip"
"io"
"log"
"os"
"path/filepath"
)
@jasdeepkhalsa
jasdeepkhalsa / longPolling.js
Last active April 17, 2024 10:59
Simple Long Polling Example with JavaScript and jQuery by Tian Davis (@tiandavis) from Techoctave.com (http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery)
// Long Polling (Recommened Technique - Creates An Open Connection To Server ∴ Fast)
(function poll(){
$.ajax({ url: "server", success: function(data){
//Update your dashboard gauge
salesGauge.setValue(data.value);
}, dataType: "json", complete: poll, timeout: 30000 });
})();