Skip to content

Instantly share code, notes, and snippets.

View frhd's full-sized avatar
🏠
Working from home

farhad frhd

🏠
Working from home
  • quantyc
  • Göttingen, Germany
  • 12:37 (UTC +02:00)
  • X @frhd27
View GitHub Profile
@frhd
frhd / lua_file.lua
Created November 21, 2013 16:32
Writing to file in lua 5.2
local file = io.open("example.txt", "a") -- a for append, w for overwrite all
file:write("Dont think you are. Know you are.")
file:close()
@frhd
frhd / c++ check if file exists
Last active December 30, 2015 05:49
c++ check if file exists
// Get the full path of the .exe, ANSI format
string ExePath() {
char buffer[MAX_PATH];
GetModuleFileNameA( NULL, buffer, MAX_PATH );
string::size_type pos = string( buffer ).find_last_of( "\\/" );
return string( buffer ).substr( 0, pos);
}
// Check if file exists
bool IniFileExists(string file) {
@frhd
frhd / c++ cycle clockin
Created December 10, 2013 15:57
c++ cycle clocking
clock_t start = clock();
for (int it = 0; it < 1000000; ++it)
foo(s);
printf("foo took %i cycles\n", clock() - start);
@frhd
frhd / tail a directory
Created January 29, 2014 09:31
Linux: Tail a directory
watch "ls -lrt | tail -10"
@frhd
frhd / create lots of files
Created January 29, 2014 10:03
create lots of files
# create master file
dd if=/dev/zero of=masterfile bs=1 count=1000000
# split master file
split -b 10 -a 10 masterfile
@frhd
frhd / css div fadeout
Created February 3, 2014 14:47
css div fadeout
#fadeout {
z-index: 50;
position: fixed;
left: 0;
top: 0;
right: 0;
height: 100px;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 255)), to(rgba(255, 255, 255, 0)));
background: -moz-linear-gradient(top, rgba(255, 255, 255, 255), rgba(255, 255, 255, 0));
@frhd
frhd / css less #1
Created February 7, 2014 12:36
css less negative numbers and absolute centering
@divwith: 1600px;
.superdiv {
overflow: auto;
height: 100%;
position: absolute;
width: @divwith;
margin-left: -(@divwith/2);
left: 50%;
}
@frhd
frhd / CoffeeScript One Liners
Last active August 29, 2015 13:56
CoffeeScript One Liners
# @ricardo.cc
# Multiply each item in a list by 2
[1..10].map (i) -> i*2
# or
i * 2 for i in [1..10]
# Sum a list of numbers
[1..1000].reduce (t, s) -> t + s
@frhd
frhd / Parsing JSON in Java
Created February 18, 2014 14:10
Parsing JSON in Java
JSONObject obj = new JSONObject("{interests : [{interestKey:Dogs}, {interestKey:Cats}]}");
List<String> list = new ArrayList<String>();
JSONArray array = obj.getJSONArray("interests");
for(int i = 0 ; i < array.length() ; i++){
list.add(array.getJSONObject(i).getString("interestKey"));
@frhd
frhd / infinite loop
Created February 20, 2014 10:29
infinite loop threading etc
public class Main {
public static volatile int x = 0;
public static void main(String[] args) {
LoopingThread t = new LoopingThread();
t.start();
while (true) {
x = x++;
}
}
}