Skip to content

Instantly share code, notes, and snippets.

View chirag64's full-sized avatar

Chirag Bhatia chirag64

View GitHub Profile
// Recursive function to flatten out a multi-dimensional array
function FlattenArray(arr) {
var newArr = [];
for (var i = 0; i < arr.length; i++) {
// Go through each elements of array, if element is array, call this function with it as parameter and then concatenate
// with the new array, else just add the element to the new array, then return the new array in the end
if (Array.isArray(arr[i])) {
newArr = newArr.concat(FlattenArray(arr[i]));
}
else {
// Prints a Pascal Triangle of 'n' no. of lines
function PascalTriangle(n) {
var arr = [];
for (var i = 0; i < n; i++) {
// Create an array
arr[i] = [];
// Mark 1st and last element as 1
arr[i][0] = 1;
arr[i][i] = 1;
Dim speaks, speech
If (Minute(Time()) = 0) Then
speaks = "It is now " & (((Hour(Time()) + 11) Mod 12) + 1) & " O' clock"
Else
speaks = "The time is now " & (((Hour(Time()) + 11) Mod 12) + 1) & " " & Minute(Time())
End If
Set speech = CreateObject("sapi.spvoice")
speech.Speak speaks
@chirag64
chirag64 / NewsHighlight.js
Last active January 19, 2016 13:33
A quick and hacky script to fetch key sentences from a blog or news article. Basically fetches the sentences with most words in them.
// Get all sentences
var sentences = document.body.innerText.split(".");
// Remove all sentences with newline characters in them since they're likely tags or sidebar data
for (i=sentences.length - 1; i>-1; i--)
{
if (sentences[i].trim().indexOf("\n") !== -1)
{
sentences.splice(i,1);
}
-- MarI/O by SethBling
-- Feel free to use this code, but please do not redistribute it.
-- Intended for use with the BizHawk emulator and Super Mario World or Super Mario Bros. ROM.
-- For SMW, make sure you have a save state named "DP1.state" at the beginning of a level,
-- and put a copy in both the Lua folder and the root directory of BizHawk.
if gameinfo.getromname() == "Super Mario World (USA)" then
Filename = "DP1.state"
ButtonNames = {
"A",
# Watch a file changes in the current directory,
# Execute all tests when a file is changed or renamed
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = Get-Location
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $false
$watcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite -bor [System.IO.NotifyFilters]::FileName
while($true)
# How to use:
#
# Dependencies - scort, imagemagick, i3lock
#
# Just place a lock.png in your home folder to overlay whatever you want
#!/bin/bash
scrot -e 'convert -blur 0x3 $f ~/lockbg.png'
convert -gravity center -composite ~/lockbg.png ~/lock.png ~/lockfinal.png
i3lock -i ~/lockfinal.png -p default -e
if (Object.defineProperty && Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(Element.prototype, "textContent") && !Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get) {
(function() {
var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText");
Object.defineProperty(Element.prototype, "textContent",
{
get: function() {
return innerText.get.call(this);
},
set: function(s) {
return innerText.set.call(this, s);
@chirag64
chirag64 / AfterRunning.ps1
Created November 20, 2014 06:19
Execute something after a process has ended via PowerShell
function AfterRunning {
param (
[String] $Process
)
while ((Get-Process $Process -ErrorAction SilentlyContinue | Select-Object -ExpandProperty ProcessName) -ne $null) {
Start-Sleep -Seconds 2
Write-Host "Process still running..."
}
}
@chirag64
chirag64 / PSSnippets.ps1
Last active May 11, 2023 22:32
PowerShell snippets
#Create array of file list from a directory.
$arr = (dir).FullName #Get all files
$arr = (dir *.log).FullName #Get files of .log extension
#Get headers of file to identify its format.
Get-Content -Path FilePath -Encoding Byte -TotalCount 4
#Download File via http.
Invoke-WebRequest "http://filepath/file.jpg" -OutFile "C:\LocalPath\filename.jpg"