Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am et-cs on github.
  • I am etaycs (https://keybase.io/etaycs) on keybase.
  • I have a public key ASBHrvlxp6BouxTJaCNQXzkDfP3h7MsLTF52UAZOKvj1DQo

To claim this, I am signing this object:

@ET-CS
ET-CS / clear_log.sh
Last active May 16, 2020 15:44
Linux (CentOS) clear log script
#!/bin/bash
# this script clear logs in Linux (made in CentOS)
cd /var/log
truncate -s 0 /var/log/*log
find . -name "*.gz" -type f -delete
find . -name "*.0" -type f -delete
find . -name "*.1" -type f -delete
find . -name "*.log.*" -type f -delete
@ET-CS
ET-CS / get_stackoverflow_user_data
Created June 26, 2015 04:43
python stackoverflow get reputation and badge count
#!/usr/bin/env python
import requests
import simplejson as json
# this function fetch your user data from the so api
def get_data():
# replace '3879958' with your userid
url = "https://api.stackexchange.com/2.2/users/3879958?order=desc&sort=reputation&site=stackoverflow"
j=json.loads((requests.get(url, timeout=5)).text)
return j
@ET-CS
ET-CS / notify_space.sh
Created January 29, 2015 01:35
Send yourself an email if your CentOS server has less than 10% free space.
#!/bin/sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 90 ]; then
echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep%" youremail@example.com
fi
done
@ET-CS
ET-CS / get_twitter_followers.py
Created June 3, 2014 22:51
Get Twitter Followers in Python
import twitter
from twitter import TwitterError
TWITTER_CONSUMER_KEY = 'your consumer key'
TWITTER_CONSUMER_SECRET = 'your consumer secret'
TWITTER_ACCESS_TOKEN_KEY = 'your token key'
TWITTER_TOKEN_SECRET = 'your token secret'
def get_twitter_followers():
try:
@ET-CS
ET-CS / websites-tester.sh
Last active August 29, 2015 14:02
Bash shell script file to test websites availability and email if status is offline
#!/bin/bash
# This script made in centos - you may need to change the command above according to your system
# ------------------------------------------
# Website status checker.
# save all websites to check in file named 'websites.txt'. each in new line.
# end file with empty line.
# ------------------------------------------
# Quiet mode. enable to disable echo's command. for crontab, etc.
@ET-CS
ET-CS / get_youtube_subscribers.py
Last active January 4, 2016 04:58
Python - get YouTube followers using API (v3)
import requests
import simplejson as json
# UPDATED to use API (v3)
def get_youtube_followers():
url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername=[UserName]&key=[API-Key]"
j=json.loads((requests.get(url, timeout=5)).text)
return j['items'][0]['statistics']['subscriberCount']
@ET-CS
ET-CS / get_github_followers.py
Last active January 4, 2016 04:58
Python - get GitHub followers
import requests
import simplejson as json
def get_github_followers():
url = "https://api.github.com/users/ET-CS"
j=json.loads((requests.get(url)).text)
return str(j['followers'])
@ET-CS
ET-CS / TwoStatePreferenceActivity.java
Last active October 22, 2018 16:17
How to implement TwoState using CheckBoxPreference / android development
public class PreferencesActivity extends PreferenceActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// find the CheckBox
CheckBoxPreference chkbox = (CheckBoxPreference) findPreference(getString(R.string.chkboxid));
// set OnClick listener
chkbox.setOnPreferenceClickListener(chkboxListener);
public class MyService extends IntentService {
...
private class DisplayToast implements Runnable{
String mText;
public DisplayToast(String text){
mText = text;
}