Skip to content

Instantly share code, notes, and snippets.

@mrahul17
mrahul17 / List
Last active November 8, 2015 08:19
A list of additional Ubuntu repositories and Python Modules that I installed. The ultimate aim is to write a bash script that will reinstall all of these if I ever have to do a fresh installation of Ubuntu.
scrapy
BeautifulSoup
Nautilius-actions
ezodf
Pillow
requests
@mrahul17
mrahul17 / gist:4339dd1eae7ed4e9acb1
Last active August 29, 2015 14:13
Important and fundamental questions for C and C++
http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member
http://stackoverflow.com/questions/6500313/why-should-c-programmers-minimize-use-of-new
http://stackoverflow.com/questions/655065/when-should-i-use-the-new-keyword-in-c
http://www.gotw.ca/gotw/009.htm
http://stackoverflow.com/questions/3162030/difference-between-angle-bracket-and-double-quotes-while-including-heade
@mrahul17
mrahul17 / gist:efdf94f91922d04ef5d3
Last active August 29, 2015 14:15
Questions regarding Ruby
http://stackoverflow.com/questions/1274675/ruby-what-does-warray-mean
http://stackoverflow.com/questions/4370960/what-is-attr-accessor-in-ruby
http://awaxman11.github.io/blog/2013/08/05/what-is-the-difference-between-a-block/
The last expression that is evaluated is automatically returned by the method
http://queirozf.com/entries/ruby-map-each-collect-inject-reject-select-quick-reference
#ffmpeg
http://superuser.com/questions/675342/convert-mp3-to-wav-using-ffmpeg-for-vbr
http://stackoverflow.com/questions/548766/writing-module-for-ruby
1) How can I give write-access of a folder to all users in linux?
http://superuser.com/a/19333/402332
2)cant-create-any-folder-in-htdocs-on-ubuntu
http://superuser.com/a/268996/402332
3) change remote origin
http://stackoverflow.com/questions/2432764/change-the-uri-url-for-a-remote-git-repository
4)when files not ignored even if specified in .gitignore
@mrahul17
mrahul17 / lines and levels
Created March 14, 2015 08:49
Tardis data set
>>> lines_data[0]
(8, 66.772, 14, 5, 0.027030168289315495, 0.04054525243397324, 0.0, 36.0, 4.489792997064637e+16, 45453772.17738786, 30302514.784925245, 40439167617.50947)
>>> lines_data[0]
(8, 66.772, 14, 5, 0.027030168289315495, 0.04054525243397324, 0.0, 36.0, 4.489792997064637e+16, 45453772.17738786, 30302514.784925245, 40439167617.50947)
>>> lines_data[1]
(10, 69.204, 14, 5, 0.0866842126131329, 0.0866842126131329, 0.0, 35.0, 4.332010548523206e+16, 100717918.92086083, 100717918.92086083, 120731290053.8376)
>>> lines_data[2]
(11, 69.236, 14, 5, 0.06192253818286209, 0.09288380727429314, 0.0, 34.0, 4.330008348258131e+16, 107971097.37718476, 71980731.58478984, 86164235409.22531)
>>> lines_data[3]
(12, 69.448, 14, 5, 0.01769864460960345, 0.0353972892192069, 1.0, 35.0, 4.316790375532773e+16, 41272928.49085178, 20636464.24542589, 24477257110.58792)
@mrahul17
mrahul17 / gist:cd1c2f78e04a7d39edec
Created April 12, 2015 09:37
List of new python functions and FAQs
What is the use of assert in python
http://stackoverflow.com/questions/5142418/what-is-the-use-of-assert-in-python
An important difference is that assert statements get ignored if you compile your code with the optimization option.
Safely using eval
http://lybniz2.sourceforge.net/safeeval.html
with open('instiDatacsv.csv','r') as f:
myReader = csv.reader(f)
for row in myReader:
name = row[1]
website = row[5]
domain = row[4]
insti = Institute(name = name, website = website)
insti.save()
InstituteDomain(instituteId = insti, domain = domain).save()
@mrahul17
mrahul17 / ipow.c
Created December 9, 2015 13:53 — forked from orlp/ipow.c
int64_t ipow(int32_t base, uint8_t exp) {
static const uint8_t highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 255, // anything past 63 is a guaranteed overflow with base > 1
@mrahul17
mrahul17 / exponent.cpp
Created December 9, 2015 13:55
Exponentiation by squaring
int ipow(int base, int exp)
{
int result = 1;
while (exp)
{
if (exp & 1)
result *= base;
exp >>= 1;
base *= base;
}
// Taken from http://stackoverflow.com/questions/98153/whats-the-best-hashing-algorithm-to-use-on-a-stl-string-when-using-hash-map
unsigned int hash(const char* s, unsigned int seed = 0)
{
unsigned int hash = seed;
while (*s)
{
hash = hash * 101 + *s++;
}