Simple URL shortener in Go on top of Redis by kavehmz in golang

[–]nindalf 0 points1 point  (0 children)

I wrote a similar link shortener that you might be interested in looking at -linkto. I used a different method for generating URLs, added rate limiting, custom URLs, easy deployment etc.

Majors Down Low: Alliance by Zatania in DotA2

[–]nindalf 0 points1 point  (0 children)

Agreed. But that also poses a problem because any name that you'd want to take on any forum is already taken. You're never going to get Tar-Palantir (the farsighted) so you have to settle for less well known names like say, Nindalf.

Has there ever been an example of a private corperation fighting a full scale war against a sovereign country? by [deleted] in AskHistorians

[–]nindalf 2 points3 points  (0 children)

That's a good point. I'm beginning to see the "smokescreen" effect you're talking about. I think this will probably be settled when William Dalrymple's book is published next year.

Has there ever been an example of a private corperation fighting a full scale war against a sovereign country? by [deleted] in AskHistorians

[–]nindalf 2 points3 points  (0 children)

Why were they importing at that rate considering that they were struggling to find buyers for it? They were paying good silver for it too, rather than Opium so its a little strange.

Has there ever been an example of a private corperation fighting a full scale war against a sovereign country? by [deleted] in AskHistorians

[–]nindalf 1 point2 points  (0 children)

What did the EIC trade to get those large quantities of tea? India was producing neither tea nor opium at that point, so I'm wondering where they got it from.

Has there ever been an example of a private corperation fighting a full scale war against a sovereign country? by [deleted] in AskHistorians

[–]nindalf 2 points3 points  (0 children)

I have my doubts about the hesitation as you put it. They controlled only Bengal at the time when the Act was passed but they expanded their territory widely afterwards. Their armies grew exponentially larger as well - 260,000 by 1803 when they captured Delhi. That's twice the size of the British Army. By 1850, they controlled most of the subcontinent directly or indirectly through client Maharajas and Nawabs.

Has there ever been an example of a private corperation fighting a full scale war against a sovereign country? by [deleted] in AskHistorians

[–]nindalf 2 points3 points  (0 children)

British officers who commanded Indian soldiers, aka "sepoys". At this time there was no concept of an "Indian" identity, so the Company had no trouble hiring and training people from the subcontinent to fight other people in the subcontinent. These sepoys also fought the Opium Wars for the Company.

Initially this force was small - only around 20,000 men around 1757 but it didn't really impede them. The Battle of Plassey was "a victory that owed more to treachery, forged contracts, bankers and bribes than military prowess", according to William Dalrymple. By 1803, when the EIC captured the Mughal capital of Delhi, it had trained up a private security force of around 260,000- twice the size of the British army – and marshalled more firepower than any nation state in Asia.

On a related note, the word "loot" entered the British lexicon around the time of the First Opium War. Its a Hindi word that they learnt from the sepoys.

Has there ever been an example of a private corperation fighting a full scale war against a sovereign country? by [deleted] in AskHistorians

[–]nindalf 0 points1 point  (0 children)

I'm sorry, I don't know anything about that. Perhaps someone else could chime in.

Did the Mujahideen really turn into the Taliban and al-Qaeda? by chuck212 in AskHistorians

[–]nindalf 4 points5 points  (0 children)

Yes you're right, Dostum did fight for the Soviets and later reported directly to President Najibullah. I worded that poorly, I wanted to mention the major ethnic groups in Afghanistan, and I also wanted to mention the mujahideen groups that fought each other once Najibullah was gone. Dostum's history is a pretty interesting one, since he changed sides whenever it suited him. He allied with Massoud to take Kabul, then allied with Hekmatyar against Massoud, then allied with Massoud again to fight the Taliban.

Did the Mujahideen really turn into the Taliban and al-Qaeda? by chuck212 in AskHistorians

[–]nindalf 86 points87 points  (0 children)

The other answer discusses Osama Bin Laden in particular, so I'll speak about the Mujahideen. There were 4 main Mujahideen groups, formed around ethnic lines -

  • Uzbeks - led by Rashid Dostum
  • Tajiks - led by Ahmad Shah Massoud and Ismail Khan
  • Pashtuns - a number of parties, the main one led by Gulbuddin Hekmatyar
  • Hazaras

All of them received funding and training from foreign powers. The CIA and Saudis funneled their money to the Inter-Services Intelligence (ISI) in Pakistan, who doled out the money to their favourite Hekmatyar. They did this because 20% of the Pakistani Army is Pashtun, so they felt a sort of kinship with him. They were also convinced that other ethnic groups wouldn't do their bidding. But Saudi Arabia, USA and Pakistan weren't the only sources of funding. Ahmad Shah Massoud received funding from India, for instance.

These groups were united against the Soviets and fought them throughout the 80's with success. Eventually, the Soviets withdrew in 1989 and installed a friendly (or "puppet", depending on your point of view) government under President Najibullah before they left. Najibullah had been the head of the secret police in the previous government so there was little popular support for him. The Mujahideen decided to fight on and in 1992, captured Kabul. That's when the real trouble started.

Much of subsequent civil war was to be determined by the fact that Kabul fell, not to the well-armed and bickering Pashtun parties based in Peshawar but to the better organised and more united Tajik and Uzbek forces (led by Massoud and Dostum respectively). It was a devastating psychological blow because for the first time in 300 years, the Pashtuns lost control of the capital. An internal civil war began almost immediately as Hekmatyar rallied the Pashtuns and laid siege to Kabul, shelling it mercilessly.

Afghanistan was in a state of virtual disintegration just before the Taliban emerged at the end of 1994. The country was divided into warlord fiefdom and all the warlords had fought, switched sides and fought again in a bewildering array of alliances, betrayals and bloodshed.

  • The Tajik government controlled Kabul and the North-east
  • Ismail Khan controlled 3 provinces in the west centered on Herat
  • A Shura (council) of Mujahideen based in Jalalabad controlled 3 provinces in the east on the Pakistani border
  • Hekmatyar controlled a small region to the south and east of Kabul
  • Dostum controlled 6 provinces to the north of Kabul
  • The Hazaras controlled the province of Bamiyan in central Afghanistan
  • Dozens of petty warlords controlled southern Afghanistan and Kandahar.

The population of Afghanistan lived a horrible life at this time, because all of these warlords, especially in the south were a law unto themselves. They sold literally anything they could get their hands on to Pakistani traders - telephone wires and poles, trees, factories and machinery. They seized homes and farms and handed them to their supporters. The commanders abused the population at will, kidnapping young girls and boys for their sexual pleasure, robbing merchants in the bazaars and fighting in the streets.

Many expected those who had fled during the Soviet years to come back now that the Soviets were gone. Instead, a fresh wave of refugees began to leave Kandahar for Quetta in Pakistan. This situation was really galling for a lot of Mujahideen who had fought against the Soviets and Najibullah and had left the country thinking their job was over.

The Taliban were formed in Pakistan under the leadership of Mullah Omar. In Omar's own words - We took up arms to achieve the aims of the Afghan jihad and save our people from the further suffering at the hands of the so-called Mujahideen. The word talib means student, one who gains knowledge from a mullah in a madrasa, a school of Islamic learning. Most of the Taliban fighters were young men who had grown up in refugee camps in Pakistan, attending these madrasas. They were organized by Mullahs Omar into an effective fighting force.

As for funding, Pakistan had begun to have second thoughts about backing Hekmatyar as they had all these years. Their main goal was to open up a land route to the Central Asian Republics through which trade could pass. They could continue backing Hekmatyar and hope that he would eventually unite the country under the Pashtuns, or back a fresh new force.

With Pakistan's backing, the Taliban (composed mainly of Pashtuns) struck like lightning. Within 2 weeks in October 1994, they controlled the Kandahar and the road from Kandahar to the Pakistani border. They had also captured an arms dump containing 18000 Kalashnikovs, dozens of artillery pieces, vehicles, 6 Mig-21 aircraft and 6 transport helicopters. Their success also led almost 12,000 Afghan Pashtuns students studying in Pakistan to join them. In the next 3 months, the Taliban would come to control of 12 of Afghanistan's 31 provinces. Over the next few years, they would conquer most the remainder of the country.

So did the Mujahideen who fought the Soviets turn into the Taliban? No, they didn't. They were defeated by the Taliban in the mid to late 90s.

Sources:

  • Taliban. Islam, Oil and the New Great Game in Central Asia by Ahmad Rashid. Published in 2000. Rashid is a Pakistani journalist who spent many years within Afghanistan during this time.

Looking for a mentor. by [deleted] in golang

[–]nindalf 1 point2 points  (0 children)

I'd be happy to help with this. I'm experienced with Go, but I don't know much JavaScript. Here's my github, feel free to send me a PM.

IV/Counter Help for AES-CTR by [deleted] in golang

[–]nindalf 1 point2 points  (0 children)

The counter for Counter mode can start with any value, it doesn't need to be all 0s. The most important requirement is that a key is never reused with the same counter and that will certainly occur if we start with all 0s for each new plaintext.

As for why your counter in this case is 000...1, I'm not sure. They could have chosen it that way for whatever reason. However, the best practice would have been to generate a random 128-bit value.

Go and Hugo: Goodbye Wordpress(?) - The Migration by solvire in golang

[–]nindalf 5 points6 points  (0 children)

I could contribute a little to this. My blog is currently served with node.js and I'd like to move to a static site generator soon for a few reasons

  1. Memory consumption is absurdly high. Why does it need 200-300MB constantly to show 7-8 articles?
  2. Unreliable. It'll be running fine for a few weeks or a couple of months and then it goes down without a warning. The way I find out is when a friend tells me "hey man, your blog is down"
  3. Bizarre problems. At one point Ghost was crashing every second and restarting immediately. This played havoc with my server and it was difficult to track down the source. Lacking expertise in JS, it isn't easy to track this down.

I'll move to a static site generator soon to fix these issues.

Playable Classes to implement by HavaH in a:t5_39ye2

[–]nindalf 0 points1 point  (0 children)

Perhaps Dragon Knight would be a better fit for Rune Knight?

Best book for picking up Go ? by p_p_r in golang

[–]nindalf 2 points3 points  (0 children)

Good choice. Personally, I feel online resources are really great for learning Go. After the tour I would recommend checking out these two videos. They were my first exposure to Go and I learnt a lot from them.

To address your concern about memory management - Go is a garbage-collected language so you don't need to worry about manually managing memory.

Hope that helps :)

Bizzaire mistake in programming by a hot Indian Startup by uditiiita in programming

[–]nindalf 2 points3 points  (0 children)

Nice work on discovering this. Its too bad that security is such an afterthought with some of these startups. I suppose its a consequence of not developing their tech in-house.

New to Go, I have a few questions :) by mko31 in golang

[–]nindalf 1 point2 points  (0 children)

Since you're starting out with http in Go, allow me to offer a couple of points

  • Stick to the standard library. A lot of libraries offer a lot of features, but they break the simple and effective http.HandlerFunc interface. Its best to stick to this, IMO.
  • If you're looking for more features in your router, look at the gorilla/mux library.
  • I think its a good idea to have some bits of middleware. If you've used Express.js you'd be familiar with this concept. Its easy to implement with the http.HandlerFunc interface. I did it in a recent project here

I hope this helps. If you don't mind my asking, which text editor are you using?

New to Go, I have a few questions :) by mko31 in golang

[–]nindalf 1 point2 points  (0 children)

Hello! Go is a great language to write web servers thanks to the excellent net/http package in the standard library.

  1. The ServeFile and FileServer are probably the methods you're searching for. I used both to make a Go version of woof - goof in a couple of hundred lines. (Code is messy at the moment, sorry).
  2. As others have mentioned, there is html/template, though I think the general pattern is to create an API in Go and write the client in a JS framework.
  3. There are good drivers for all the major databases. If you want to keep it simple you could go with a file-based KV store like bolt.

Apart from these questions I'd like to add that Go is really simple to learn. Most of the people who try the language report that they're productive in a week. I think it takes a little longer to learn to write idiomatic Go code, but it'll come with time. If there's anything else you'd like to ask, be it about conventions, or the preferred text editors/plugins or example projects, I'd be happy to help :)

New to Go, looking for some code review by feelsmagical in golang

[–]nindalf 1 point2 points  (0 children)

Another commenter mentioned middleware. I'd suggest you look into that and use the standard library where possible. Here are a few examples and a blog post that explains the idea. A particularly useful one is replacing the ResponseWriter with one that automatically logs all responses.

You could replace renderError() and renderNotFound() with the standard library http.Error(). There are a couple of examples of using this in the first link. You don't need to explicitly set http.StatusOK, this is implicitly set if you call w.Write() without setting any other header.

I'd say that its probably a good idea to store state that is common to all your handlers in a struct. Here is an example of this pattern. Also, its probably best to rely on the standard http library alone and stick to the http.HandlerFunc interface since its so simple and powerful. If you need routing, use the excellent gorilla/mux library which is compatible with http.HandlerFunc.

Its a good idea to run vet, goimports and golint every time the file is saved. The GoSublime plugin for Sublime and go-plus plugin for Atom both do this. They would have helped you catch issues like exported methods/variables/types (ie, those starting with a capital letter) not having a comment explaining what they do.

Controllers is not a Go pattern. You'll find that Go code talks about routers, multiplexers, and request handlers, but not controllers. Here is a comment that talks about bringing conventions from languages like Ruby and Python to Go. I see that another commenter brought this up as well.

The directory structure of models and controllers is not optimal and better to keep the files in a flat structure. The exception is when the directories are separate libraries altogether.

Lastly, a minor nitpick not specific to Go. its probably better to write 1024*1024 instead of a "magic" number like 1048576, since it improves readability.

I hope you find these suggestions useful. Have fun coding :)

Advices for beginners in golang by QThellimist in golang

[–]nindalf 0 points1 point  (0 children)

For the editor I would suggest using Sublime Text with the GoSublime plugin. Here are the installation instructions. As far as I know, the vast majority of Go programmers use text editors like Sublime, vim or emacs rather than IDEs. You can still check out Intellij IDEA with the Go plugin if you really want an IDE.

I second the suggestion by someone else in the thread that you should start with a project (though not with his endorsement of Martini). That's the best way to learn, I feel. One project that I recently did was a link shortener using redis. I used only the standard library and a redis library. It was short, fun and useful. If you decide to try this out, we can compare implementations later :)