Skip to content

Instantly share code, notes, and snippets.

View aavrug's full-sized avatar
🏃‍♂️
Focusing

Gaurav Kumar aavrug

🏃‍♂️
Focusing
View GitHub Profile
f = open(hello_file, 'a+')
f.seek(-1,2)
if f.read():
path = '\n'+path
f.write(path)
def get_username():
return pwd.getpwuid(os.getuid()).pw_name
@aavrug
aavrug / checkbox-field
Created November 18, 2016 08:54
Checkbox field for Wordpress plugin
printf(
'<input id="%1$s" name="jo_plugin_options[%1$s]" type="checkbox" %2$s />',
'jo_checkbox_del',
checked( isset( $this->options['jo_checkbox_del'] ), true, false )
);
@aavrug
aavrug / jstree-refresh.js
Created November 16, 2016 03:28
For refreshing the jstree data
$("#frmt").jstree(true).refresh(false, true);
@aavrug
aavrug / gist:2d7af40e487920d2081d085853f6814c
Last active November 8, 2016 08:55
Upload File using ist and use that into PHP method
//js code
$('.file-field:file').on('change', function() {
var file_data = this.files[0];
var form_data = new FormData();
form_data.append('file', file_data);
var formUrl = 'upload.php';
$.ajax({
url: formUrl,
dataType: 'text',
cache: false,
A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape.
Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].
The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|
In other words, it is the absolute difference between the sum of the first part and the sum of the second part.
For example, consider array A such that:
//Previous code
a = list(map(int, raw_input().split()))
for i in a:
if a.count(i) == 1:
print i
break
// Current code
from collections import Counter
@aavrug
aavrug / scrollbar styling
Created August 29, 2016 11:34
Scrollbar styling
//Markup
<div class="scrollbar" id="style-1">
<div class="force-overflow"></div>
</div>
//CSS
#style-1::-webkit-scrollbar-track
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
@aavrug
aavrug / docker-commands.txt
Last active June 29, 2016 03:19
Docker commands
// For pulling a docker image
docker pull <image-name>
// For building docker image
docker build .
// For removing a docker image
docker rmi <imageid>
// For forcefully removing a docker image
@aavrug
aavrug / gist:4e36272cbca4f258ba01e8eaf4484f22
Created May 3, 2016 08:25
Search and replace react id
find . -type f -exec grep -l 'data-reactid' {} \; | while IFS='' read -r line; do perl -pi -e 's/(data-reactid=")[^"]+(")/\1\2/g' "$line"; done